package cn.zyl.watchfaceblackfashion;

import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.PowerManager;
import android.os.RemoteException;
import android.util.AttributeSet;
import android.util.Log;
import android.view.ContextThemeWrapper;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;

import com.tencent.tws.api.ILbsApiService;
import com.tencent.tws.api.LBSWeatherResult;
import com.tencent.tws.api.WeatherInfo;
import com.tencent.tws.api.healthkit.Health;
import com.tencent.tws.api.healthkit.HealthKitResponse;
import com.tencent.tws.api.healthkit.IHealthKitService;
import com.tencent.tws.api.healthkit.RequestHealthResult;
import com.tencent.tws.qdozemanager.QDozeManager;
import com.tencent.tws.watchfaceimpl.IWatchface;
import com.tencent.tws.watchfacelib.BroadcastReceiverManager;
import com.tencent.tws.watchfacelib.CommonUtils;
import com.tencent.tws.watchfacelib.LunarCalendar;
import com.tencent.tws.watchfacelib.ServiceConnectionManager;
import com.tencent.tws.watchfacelib.ZylUtils;

import org.apache.http.cookie.CookieAttributeHandler;
import org.ini4j.Config;
import org.ini4j.Profile;
import org.ini4j.Wini;

import java.io.File;
import java.io.FileReader;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import cn.zyl.functions.AppTools;
import cn.zyl.functions.StopWatch;
import cn.zyl.functions.TextTools;

public class FashionBaseView
  extends View
{

  private int frameTop = 15;  //默认15帧每秒吧
    private int INTERVAL_MILLIS = 1000/frameTop;
  private final int MSG_LBS = 2;
  private final int MSG_START = 1;
  private int SCREEN_HEIGHT;
  private int SCREEN_WIDTH;
  private String TAG = getClass().getSimpleName()+"_zyltest";
  private IWatchface.ICallbackFinished dozeCallback;
  boolean isCharging;
  private boolean isDoze = false;

  private float mBLevelAction;

  //==============自定义变量(新)=================
  private String sdCard = Environment.getExternalStorageDirectory().getAbsolutePath();
    private String cName;  //当前加载表盘文件夹名
  private Map<String,Typeface> fonts = new HashMap<String,Typeface>();  //字体
  private Map<String,Bitmap> pics = new HashMap<String,Bitmap>();  //图片
  private List<String> pics_hide = new ArrayList<String>();  //隐藏显示用的图片
    private Map<String,StopWatch> stopWatches = new HashMap<String,StopWatch>();  //计时器数组
    private Map<String,Float> spins = new HashMap<String,Float>();  //旋转角度数组
    public Map<String,Float> RVLT_spins = new HashMap<String,Float>();  //旋转角度数组(公转)
    private Map<String,Integer> switchs = new HashMap<String,Integer>();  //切换数组
    private Map<String,Integer> framesjump = new HashMap<String,Integer>();  //{Spin}和{Switch}低于15帧的时候跳帧控制
    private Map<String,Integer> RVLT_framesjump = new HashMap<String,Integer>();  //{Spin}和{Switch}低于15帧的时候跳帧控制(公转)
  private String DayHour = "8";  //白天开始时间，默认8点
  private String NightHour = "20";  //夜晚开始时间，默认20点
  private String SecondType = "run";   //默认是跑针吧,walk是走针
  public int ScreenOn = -1;   //默认-1=系统默认,0是长亮吧，单位秒
  public int ScreenOnFlash = 60;   //单位分,长亮模式下几分钟后关屏1次。
  private List<Profile.Section> layers = new ArrayList<Profile.Section>();  //配置层
  private int showBattery100Level=0;   //电量%
    public boolean showWeather = false;  //是否显示天气
  private int mTemperature = 0;   //温度
  private int mWeatherIndex = 0;   //天气索引
  private String mWeatherDesc = "";   //天气描述
    public boolean showStep = false;  //是否显示步数
    private int mStep = 0;   //当前步数
    private boolean mBCharge = false;
    public boolean isDim = false;  //是否开启dim模式
    public boolean isDimRunning = false;  //是否正在运行dim模式
    private int dimBrightness = 50;   //dim模式亮度,默认50吧，因为系统最低亮度为60
    private int dimFlashTime = 1;  //单位分钟
    private int dimEnterTime = 15;  //几秒进入dim模式，单位秒
  //==============自定义变量(新)=================

  BroadcastReceiverManager mBReceiver = new BroadcastReceiverManager(getContext())
  {
    public void onReceive(Context paramAnonymousContext, Intent paramAnonymousIntent)
    {
      String action = paramAnonymousIntent.getAction();
        try
        {
      if (action.equals("cn.zyl.watchface.change")){
        //自定义表盘切换通知，重新加载一下
        Log.d("zyltest",action);
          zylScreenChangeFace();
          if (showWeather)
              unbindLBSService();
          if (showStep)
              unbindHealthKitService();
          unloadBitmapRes();  //先取消其它的图片资源先
        loadMyWatchFace();
          zylScreenOn();  //亮屏代码再执行一下
          if (showWeather)
              bindLBSService();
          if (showStep)
              bindHealthKitService();
      }
//            if (action.equals("cn.zyl.watchface.change.stop")){
//                FashionFace fashionFace = (FashionFace)paramAnonymousIntent.getParcelableExtra("zyltest");
//                fashionFace.mFashionBaseView.zylScreenReset();
//            }

      if (action.equals("android.intent.action.ACTION_POWER_CONNECTED")) {
        FashionBaseView.this.mBCharge = true;
      }
      if (action.equals("android.intent.action.ACTION_POWER_DISCONNECTED")) {
        FashionBaseView.this.mBCharge = false;
      }
      if (action.equals("android.intent.action.BATTERY_CHANGED"))
      {
        int status = paramAnonymousIntent.getIntExtra("status", -1);
        int scale = paramAnonymousIntent.getIntExtra("scale", 100);
        showBattery100Level = paramAnonymousIntent.getIntExtra("level", scale);
        FashionBaseView.this.mBLevelAction = ((float) showBattery100Level) / scale;
        if ((status != 2) && (status != 5)) {
          FashionBaseView.this.isCharging = false;
        }else
          FashionBaseView.this.isCharging = true;
      }
        if (("android.intent.action.DATE_CHANGED".equals(action)) || ("Action.Tws.WatchTimeChanged".equals(action)))
        {
          Log.i(FashionBaseView.this.TAG, "Intent.ACTION_DATE_CHANGED");
//          FashionBaseView.this.initTextXY();
          FashionBaseView.this.mHandler.removeMessages(2);
          FashionBaseView.this.mHandler.sendEmptyMessage(2);
        }
        if ("Action.Tws.device_connected".equals(action)) {
          Log.i(FashionBaseView.this.TAG, "action:" + action);
        }

          if ("Action.Tws.LbsGetWeatherResult".equals(action))
          {
            Log.i(FashionBaseView.this.TAG, "action:" + action);
//            if (FashionBaseView.this.m_oLSBSService != null) {
//              FashionBaseView.this.m_oLSBSService.asyncGetWeatherInfo(FashionBaseView.this.getContext().getPackageName());
//            }
//            paramAnonymousContext = (LBSWeatherResult)paramAnonymousIntent.getParcelableExtra("Result");
            FashionBaseView.this.mPN = false;
            LBSWeatherResult lbsWeatherResult = paramAnonymousIntent.getParcelableExtra("Result");
            if (lbsWeatherResult == null) {
              Log.e(FashionBaseView.this.TAG, "received weather data is null");
              return;
            }
            WeatherInfo[] weatherInfos = lbsWeatherResult.getWeatherInfos();
            if (weatherInfos.length<=0){
              Log.e(FashionBaseView.this.TAG, "weatherInfos is null or empty");
              return;
            }
            WeatherInfo weatherInfo = weatherInfos[0];
            if (weatherInfo==null){
              Log.i(FashionBaseView.this.TAG, "received weather info data is null");
              return;
            }
              Log.d("zyltest",weatherInfo.toString());
            FashionBaseView.this.mTemperature = Integer.parseInt(weatherInfo.mNewCurT);
            FashionBaseView.this.mWeatherDesc = weatherInfo.mDayWeatherDesc;
            FashionBaseView.this.mWeatherIndex = Integer.parseInt(weatherInfo.mDayWeatherIndex);
//            if (FashionBaseView.this.mTemperature<0)
//              FashionBaseView.this.mTemperature = (-FashionBaseView.this.mTemperature);
//            FashionBaseView.this.showWeatherTemp = FashionBaseView.this.showWeatherFormat.replace("C",FashionBaseView.this.mTemperature+"");
//            FashionBaseView.this.mPN = true;
          }
            if ("Action.Tws.StepGoal".equals(action)){  //总步数？
                FashionBaseView.this.mGlobalStep = paramAnonymousIntent.getIntExtra("StepGoal", 10000);
            }
            if ("Action.response.healthkit".equals(action)){
                HealthKitResponse HKRes = paramAnonymousIntent.getParcelableExtra("healthKitResponse");
                if (HKRes ==null || HKRes.resultType!=0){
                    if ((HKRes != null) && (HKRes.resultType == HealthKitResponse.FAIL_WITH_NO_CONTENT) && (FashionBaseView.this.requestHealthResult != null) && (FashionBaseView.this.requestHealthResult.getReqId() == HKRes.getReqId()))
                    {
                        FashionBaseView.this.mStep = 0;
                        Log.i(FashionBaseView.this.TAG, "not content");
                    }
                    else
                    {
                        Log.i(FashionBaseView.this.TAG, "received data is null");
                    }
                    return;
                }
                Health health = HKRes.getData().get(0);
                if (health==null || health.getHealthType() !=Health.TYPE_STEP_COUNTER){
                    Log.i(FashionBaseView.this.TAG, "health data null or not step counter type");
                    return;
                }
                FashionBaseView.this.mStep = health.value;
            }
        }
        catch (Exception e)
        {
          e.printStackTrace();
//          for (;;)
//          {
//            localRemoteException.printStackTrace();
//          }
//          paramAnonymousIntent = paramAnonymousContext.getWeatherInfos();
//          if ((paramAnonymousIntent == null) || (paramAnonymousIntent.length <= 0))
//          {
//            Log.e(FashionBaseView.this.TAG, "weatherInfos is null or empty");
//            return;
//          }
//          paramAnonymousContext = paramAnonymousContext.getWeatherInfos()[0];
//          if (paramAnonymousContext == null)
//          {
//            Log.i(FashionBaseView.this.TAG, "received weather info data is null");
//            return;
//          }
//          FashionBaseView.this.mTemperature = Integer.parseInt(paramAnonymousContext.mNewCurT);
//          if (FashionBaseView.this.mTemperature >= 0) {
//            break label543;
//          }
        }
//      }
//      FashionBaseView.this.mTemperature = (-FashionBaseView.this.mTemperature);
//      label543:
//      for (FashionBaseView.this.mPN = true;; FashionBaseView.this.mPN = false)
//      {
//        FashionBaseView.this.mTempX = (FashionBaseView.this.pivotX - FashionBaseView.this.mPaint.measureText(FashionBaseView.this.mTemperature+"") / 2.0F);
//        FashionBaseView.this.mPaint.getTextBounds(FashionBaseView.this.mTemperature+"", 0, 1, FashionBaseView.this.rect);
//        FashionBaseView.this.mTempY = (FashionBaseView.this.mCommonUtils.dip2px(80.0F) + FashionBaseView.this.rect.height() / 2);
//        return;
//      }
    }
  };
  private BatteryStatus mBStatus;
  private Bitmap mBattery;
  private Bitmap mBatteryCharging;
  private Bitmap mBatteryFull;
  private Bitmap mBatteryHigh;
  private Bitmap mBatteryLow;
  private Bitmap mBatteryMiddle;
  private Paint mBatteryPaint;
  private Bitmap mBatteryWaring;
  private float mBatteryX;
  private float mBatteryY;
  private Bitmap mBg;
  private CommonUtils mCommonUtils;
  private Context mContext;
  private String mDate = getResources().getString(R.string.text_date_empty);
  private float mDateX;
  private float mDateY;
  private String mDate1 = getResources().getString(R.string.text_date_empty);
  private float mDate1X;
  private float mDate1Y;
  private String mDate2 = getResources().getString(R.string.text_date_empty);
  private float mDate2X;
  private float mDate2Y;
  private String mDate3 = getResources().getString(R.string.text_date_empty);
  private float mDate3X;
  private float mDate3Y;
  private String mDayOfWeek = getResources().getString(R.string.text_dayofweek_empty);
  private float mDayX;
  private float mDayY;
  private Bitmap mDimBg;
  private Bitmap mDimHourNeedle;
  private Bitmap mDimMinuteNeedle;
  public Handler mHandler = new Handler(new Handler.Callback()
  {
    public boolean handleMessage(Message paramAnonymousMessage)
    {
      switch (paramAnonymousMessage.what)
      {
      default: 
        return false;
      case 1: 
        FashionBaseView.this.invalidate();
          INTERVAL_MILLIS = 1000/frameTop;
          if (isDimRunning){
              INTERVAL_MILLIS = dimFlashTime*60000;  //dim模式60秒刷新一次,自定义
//              FashionFace.isMe = true;  //自己修改的
//              Log.d("zyltest","flashing... saveScreenBrightness");
              Log.d("zyltest","刷新时间"+INTERVAL_MILLIS);
              FashionFace.changeMySelf = false;
              ZylUtils.saveScreenBrightness(mContext,dimBrightness);  //亮度设置为100试一下,自定义
//              ZylUtils.changeAppBrightness(mContext,dimBrightness);
          }
          FashionBaseView.this.mHandler.removeMessages(1);  //这里主动清一下试试看
        FashionBaseView.this.mHandler.sendEmptyMessageDelayed(1, INTERVAL_MILLIS);
        return false;
      case 2:
        try
        {
          if (FashionBaseView.this.m_oLSBSService == null)
          {
            Log.d(FashionBaseView.this.TAG, "m_oLSBSService is null");
          return false;
          }
            if (!isDimRunning)
            FashionBaseView.this.m_oLSBSService.asyncGetWeatherInfo(FashionBaseView.this.getContext().getPackageName());
            else
                Log.d("zyltest","dim模式不更新天气吧");
          FashionBaseView.this.mHandler.sendEmptyMessageDelayed(2, 30*60*1000L);  //30分钟更新一次天气
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
        return false;
      case 1001:   //双击事件处理
          MotionEvent event = (MotionEvent)paramAnonymousMessage.obj;
            touchX = event.getX();
            touchY = event.getY();
            isTouch = true;
        return false;
//      case 2001:
//          zylScreenReset();  //设置默认写这里试试看
//          return false;
          case 15001:
              isDimRunning = true;
              FashionBaseView.this.mHandler.sendEmptyMessage(1);
              return false;
      }
    }
  });
  private float mHourAngle = 0.0F;
  private Bitmap mHourNeedle;
  private float mMinuteAngle = 0.0F;
  private Bitmap mMinuteNeedle;
  private boolean mPN = false;
  private Paint mPaint;
  private Paint mPaintPercent;
  private Resources mResources;
  private float mSecondAngle = 0.0F;
  private Bitmap mSecondNeedle;
  private ServiceConnectionManager mServiceConnection = new ServiceConnectionManager(getContext())
  {
    public void onServiceConnected(ComponentName paramAnonymousComponentName, IBinder paramAnonymousIBinder)
    {
      super.onServiceConnected(paramAnonymousComponentName, paramAnonymousIBinder);
      Log.d(FashionBaseView.this.TAG, "onServiceConnected ::::::::::::::::: bind_lbs_service_success!");
      FashionBaseView.this.m_oLSBSService = ILbsApiService.Stub.asInterface(paramAnonymousIBinder);
      if (FashionBaseView.this.m_oLSBSService == null)
      {
        Log.i(FashionBaseView.this.TAG, "m_oLSBSService is null");
        return;
      }
      try
      {
        Log.i(FashionBaseView.this.TAG, "start to load weather info");
        FashionBaseView.this.m_oLSBSService.asyncGetWeatherInfo(FashionBaseView.this.getContext().getPackageName());
//        return;
      }
      catch (Exception e)
      {
        e.printStackTrace();
      }
    }
    
    public void onServiceDisconnected(ComponentName paramAnonymousComponentName)
    {
      super.onServiceDisconnected(paramAnonymousComponentName);
      Log.d(FashionBaseView.this.TAG, "onServiceDisconnected");
    }
  };

    private ServiceConnectionManager mHealthKitServiceConncetion = new ServiceConnectionManager(getContext())
    {
        public void onServiceConnected(ComponentName paramAnonymousComponentName, IBinder paramAnonymousIBinder)
        {
            super.onServiceConnected(paramAnonymousComponentName, paramAnonymousIBinder);
            Log.v(FashionBaseView.this.TAG, "Pedometer and HealthKit onServiceConnected.");
            FashionBaseView.this.mIHealthKitService = IHealthKitService.Stub.asInterface(paramAnonymousIBinder);
            FashionBaseView.this.getTodayPedometerPeriod();
            FashionBaseView.this.getGoalStep();
        }

        public void onServiceDisconnected(ComponentName paramAnonymousComponentName)
        {
            super.onServiceDisconnected(paramAnonymousComponentName);
        }
    };

    private void getGoalStep()
    {
        try
        {
            Class localClass = Class.forName("com.tencent.tws.launcher.utils.PedometerManager");
            Object localObject = localClass.getMethod("getInstance", new Class[0]).invoke(null, new Object[0]);
            this.mGlobalStep = ((Integer)localClass.getMethod("getGoalPedometer", new Class[0]).invoke(localObject, new Object[0])).intValue();
            Log.d(this.TAG, "goalStep:" + this.mGlobalStep);
            return;
        }
        catch (ClassNotFoundException localClassNotFoundException)
        {
            localClassNotFoundException.printStackTrace();
            return;
        }
        catch (NoSuchMethodException localNoSuchMethodException)
        {
            localNoSuchMethodException.printStackTrace();
            return;
        }
        catch (IllegalArgumentException localIllegalArgumentException)
        {
            localIllegalArgumentException.printStackTrace();
            return;
        }
        catch (IllegalAccessException localIllegalAccessException)
        {
            localIllegalAccessException.printStackTrace();
            return;
        }
        catch (InvocationTargetException localInvocationTargetException)
        {
            localInvocationTargetException.printStackTrace();
        }
    }

    private void getTodayPedometerPeriod()
    {
        try
        {
            if (this.mIHealthKitService == null)
            {
                Log.w(this.TAG, "mIHealthKitService is NULL");
            }else{
                this.requestHealthResult = this.mIHealthKitService.getPedometerPeriod(getContext().getPackageName(), 0);
            }

        }
        catch (RemoteException localRemoteException)
        {
            localRemoteException.printStackTrace();
        }
    }

  private float mTempX;
  private float mTempY;

  private Typeface mTypeface;
  public ILbsApiService m_oLSBSService = null;
  public IHealthKitService mIHealthKitService = null;
    private RequestHealthResult requestHealthResult;
    private int mGlobalStep = 10000;
  private float pivotX;
  private float pivotY;
  private Rect rect = new Rect();
  
  public FashionBaseView(Context paramContext)
  {
    this(paramContext, null);
  }
  
  public FashionBaseView(Context paramContext, AttributeSet paramAttributeSet)
  {
    this(paramContext, paramAttributeSet, 0);
  }
  
  public FashionBaseView(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
  {
    super(paramContext, paramAttributeSet, paramInt);
    this.mContext = paramContext;
    this.mCommonUtils = CommonUtils.getInstance(paramContext);
    this.mPaint = new Paint();
    try
    {
      this.mTypeface = Typeface.createFromAsset(paramContext.getAssets(), "fonts/fzltqianhei_light.ttf");
      this.mPaint.setTypeface(this.mTypeface);
      this.mPaint.setARGB(255, 255, 255, 255);
      this.mPaint.setTextSize(this.mCommonUtils.dip2px(12.0F));
      this.mDate = (this.mCommonUtils.getDate() + getResources().getString(R.string.text_date_suffix));
      this.mDayOfWeek = this.mCommonUtils.getDayNameOfWeek();
      this.mBatteryPaint = new Paint();
      this.mBatteryPaint.setARGB(255, 255, 255, 255);
      this.mResources = paramContext.getResources();
      this.SCREEN_WIDTH = this.mCommonUtils.getScreenWidth();
      this.SCREEN_HEIGHT = this.mCommonUtils.getScreenHeight();
      this.pivotX = (this.SCREEN_WIDTH * 0.5F);
      this.pivotY = (this.SCREEN_HEIGHT * 0.5F);
      this.mPaintPercent = new Paint();
      this.mPaintPercent.setARGB(255, 79, 79, 79);
      this.mPaintPercent.setStyle(Paint.Style.STROKE);
      this.mPaintPercent.setStrokeWidth(2.0F);
//      return;
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
  }

  
  public boolean bindLBSService()
  {
    Intent localIntent = new Intent();
    localIntent.setAction("com.tencent.tws.commnbusiness.LBSService");
    localIntent.setPackage("com.tencent.tws.watchside");
    boolean bool = this.mServiceConnection.bindService(localIntent, Context.BIND_AUTO_CREATE);
    Log.v(this.TAG, "bindLBSService ::::::::::::::::: " + bool);
    return bool;
  }

    public boolean bindHealthKitService()
    {
        Intent localIntent = new Intent();
        localIntent.setAction("com.tencent.tws.watchside.healthkit.HealthKitService");
        localIntent.setPackage("com.tencent.tws.watchside");
        boolean bool = this.mHealthKitServiceConncetion.bindService(localIntent, Context.BIND_AUTO_CREATE);
        Log.v(this.TAG, "bindHealthKitService ::::::::::::::::: " + bool);
        return bool;
    }

    public void unbindHealthKitService()
    {
        this.mHealthKitServiceConncetion.unbindService();
    }
  
  public void checkBatteyStatus()
  {
    if (this.mBStatus == null) {
      this.mBStatus = new BatteryStatus(this.mContext);
    }
    this.mBStatus.checkBatteryState();
    this.mBLevelAction = this.mBStatus.mLevel;
  }
  
  public void dozeEntered(IWatchface.ICallbackFinished paramICallbackFinished)
  {
    this.isDoze = true;
    this.dozeCallback = paramICallbackFinished;
    invalidate();
  }
  
  public void dozeExited(IWatchface.ICallbackFinished paramICallbackFinished)
  {
    this.isDoze = false;
    this.dozeCallback = paramICallbackFinished;
    invalidate();
  }
  
  public void dozeUpdate(IWatchface.ICallbackFinished paramICallbackFinished)
  {
    this.dozeCallback = paramICallbackFinished;
    invalidate();
  }

    /**
     * 亮屏代码
     */
    public PowerManager pm=null;  //电源管理
    public PowerManager.WakeLock wakeLock=null;  //唤醒锁,时间段

    public void zylScreenReset(){
        this.ScreenOn = -1;  //恢复默认，试一下，因为虽然切换到其它表盘了，但是好像这个程序还在运行着
        zylScreenWatchDefault();
    }

    public void zylScreenChangeFace(){
        if (pm==null){
            pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        }
        if (wakeLock!=null) {
            if (wakeLock.isHeld()) wakeLock.release();  //释放
        }
//            }
        if (wakeLock==null){
            wakeLock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK,"zyl_screen");
            wakeLock.setReferenceCounted(false);
        }
        wakeLock.acquire(5000);  //切换表盘的时候亮屏5秒吧
    }

    public void zylScreenWatchDefault(){
        if (pm==null){
            pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        }
        if (wakeLock!=null){
            if (wakeLock.isHeld()) wakeLock.release();  //释放
        }
    }
    public void zylScreenOn(){
        if (this.ScreenOn==-1){
            //系统默认
            zylScreenWatchDefault();
        }else if(this.ScreenOn>0){
            if (pm==null){
                pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
            }
            if (wakeLock==null) {
                wakeLock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "zyl_screen");
                wakeLock.setReferenceCounted(false);
            }
            if (wakeLock!=null) {
                if (wakeLock.isHeld()) wakeLock.release();  //释放
            }
            wakeLock.acquire(this.ScreenOn*1000);
        }else if (this.ScreenOn==0){
            //长亮
            zylScreenOnAlways();
        }
    }


    /**
     * 长亮代码
     */
    public void zylScreenOnAlways(){
        if (this.ScreenOn==0){  //这里长亮吧
            if (pm==null){
                pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
            }
            if (wakeLock!=null) {
                if (wakeLock.isHeld()) wakeLock.release();  //释放
            }
            if (wakeLock==null){
                wakeLock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK,"zyl_screen");
                wakeLock.setReferenceCounted(false);
            }
            wakeLock.acquire(this.ScreenOnFlash*60*1000);  //默认1小时关屏亮屏一次
        }
    }

  /**
   * 加载自定义表盘
   */
  private boolean loadMyWatchFace(){
      return loadMyWatchFace(-99);
  }

  private boolean loadMyWatchFace(int initScreenOn){
    try {
//        //这里试着启动一下inwatchApp。。这个助手吧
//        try{
//            Intent intent = new Intent();
//            ComponentName comp = new ComponentName("com.example.zyl.inwatchapp","com.example.zyl.inwatchapp.VerticalListViewActivity");
//            intent.setComponent(comp);
//            intent.setAction("android.intent.action.MAIN");
//            intent.putExtra("WatchFace",true);
//            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//            mContext.startActivity(intent);
//        }catch (Exception e){
//            e.printStackTrace();
//            Log.d("zyltest","唤醒inwatchApp失败！可能没安装...");
//        }

      Log.i("zyltest",sdCard+"/zylWatchFace");
      File file = new File(sdCard+"/zylWatchFace");
      if (file.exists()) {
        //这里开始加载自定义表盘
        Log.i("zyltest","开始加载自定义表盘资源...");
        file = new File(sdCard+"/zylWatchFace/config.ini");
        if(file.exists()){
          Wini wini = new Wini(file);
          String dirName = wini.get("config","name");  //文件夹目录
            cName = dirName;
          file = new File(sdCard+"/zylWatchFace/"+dirName);
          if (file.exists()){
            //这里先把表盘目录下的字体和图片加载到变量(内存)中,还是先不加载到内存吧，这样会导致加载很慢
//            File[] pics = file.listFiles();
//            for (File pic:pics){
//              if (pic.getName().contains("config.ini"))
//                continue;
//              else if (pic.isDirectory())
//                continue;
//              this.pics.put(pic.getName(),BitmapFactory.decodeFile(pic.getAbsolutePath()));
//            }
              //字体也先不加载
//            file = new File(sdCard+"/zylWatchFace/"+dirName+"/fonts");
//            if (file.exists()&&file.isDirectory()){
//              File[] fonts = file.listFiles();
//              for (File font:fonts){
//                this.fonts.put("fonts/"+font.getName(),Typeface.createFromFile(font.getAbsolutePath()));
//              }
//            }
            file = new File(sdCard+"/zylWatchFace/"+dirName+"/config.ini");
            wini = new Wini();
            Config cfg = new Config();
            cfg.setMultiSection(true);
            wini.setConfig(cfg);
            wini.load(file);
            //读取一些配置信息吧
            String dayHour = wini.get("config","DayHour");
              DayHour = "8";
            if (dayHour!=null)
              DayHour = dayHour;
            String nightHour = wini.get("config","NightHour");
              NightHour = "20";
            if (nightHour!=null)
              NightHour = nightHour;
            String secondType = wini.get("config","SecondType");
              SecondType = "run";
            if (secondType!=null)
              SecondType = secondType;
              //dim模式下的亮屏亮度1-255,默认255，最高亮度，中=133，低=85
              String cBrightness = wini.get("config","DimBrightnessMax");
//              FashionFace.cBrightness = 255;   //这个先不处理
              if (cBrightness!=null){
                  FashionFace.cBrightness = Integer.parseInt(cBrightness);
              }
              //dim模式下的亮度1-255
              String dimBrightness = wini.get("config","DimBrightness");
              this.dimBrightness = 50;
              if (dimBrightness!=null){
                  this.dimBrightness = Integer.parseInt(dimBrightness);
              }
              //dim模式的刷新时间,分为单位
              String dimFlashTime = wini.get("config","DimFlashTime");
              this.dimFlashTime = 1;
              if (dimFlashTime!=null){
                  this.dimFlashTime = Integer.parseInt(dimFlashTime);
              }
              if (initScreenOn==-99){
                  //这里加个长亮吧
                  String screenOn = wini.get("config","ScreenOn");
                  ScreenOn = -1;
                  if (screenOn!=null)
                      ScreenOn = Integer.parseInt(screenOn);
              }else{
                  ScreenOn = initScreenOn;
              }
              //长亮模式下默认关屏亮屏一次，防止烧屏
              String ScreenOnFlash = wini.get("config","ScreenOnFlash");
              this.ScreenOnFlash = 60;
              if (ScreenOnFlash!=null){
                  this.ScreenOnFlash = Integer.parseInt(ScreenOnFlash);
              }
              //几秒进入dim模式
                String dimEnterTime = wini.get("config","DimEnterTime");
              this.dimEnterTime = 15;
              if (dimEnterTime!=null){
                  this.dimEnterTime = Integer.parseInt(dimEnterTime);
              }

            zylScreenOn();   //这里再加载一次吧
            layers = wini.getAll("layer");  //读取所有图层信息
              showWeather = false;
              showStep = false;
              isDim = false;  //默认不开启dim
              isDimRunning = false;
              this.mHandler.removeMessages(15001); //这个也先remove掉吧
//              Log.d("zyltest","loadMyWatchFace saveScreenBrightness");
              FashionFace.changeMySelf = false;
              ZylUtils.saveScreenBrightness(mContext,FashionFace.cBrightness);  //这里也恢复一下亮度试试看
//              ZylUtils.changeAppBrightness(mContext,FashionFace.cBrightness);
              for (Profile.Section layer:layers){
                  String content = layer.get("Content");
                  if (content.contains("{Weather.temp}"))
                      showWeather = true;
                  if (content.contains("{Step}")||content.contains("{Step.Spin}")){
                      showStep = true;
                  }
                  //这里判断一下是否开启dim模式
                  if (ScreenOn==0){
                      //长亮情况下才执行dim的模式
                      String show = layer.get("Show");
                      if (show.contains("dim")){
                          isDim = true;
                      }
                  }
              }
              if (isDim){
                  //如果有dim模式，那么15秒后触发dim吧
                  this.mHandler.sendEmptyMessageDelayed(15001,this.dimEnterTime*1000);
              }
          }else{
            throw new Exception("zylWatchFace/"+dirName+"文件夹不存在");
          }
        }else{
          throw new Exception("zylWatchFace/config.ini文件不存在");
        }
        Log.i("zyltest","成功加载自定义表盘资源...");
        return true;
      }
    }catch (Exception e){
      Log.i("zyltest","加载自定义表盘资源异常...");
        Toast.makeText(mContext,"加载自定义表盘资源异常..."+e.getLocalizedMessage(),Toast.LENGTH_SHORT).show();
      e.printStackTrace();
    }
    return false;
  }

  public void loadBitmapRes()
  {
    if (loadMyWatchFace())
      return;
    this.mBg = BitmapFactory.decodeResource(this.mResources, R.drawable.black_fashion_background);
    this.mHourNeedle = BitmapFactory.decodeResource(this.mResources, R.drawable.black_fashion_hour);
    this.mMinuteNeedle = BitmapFactory.decodeResource(this.mResources, R.drawable.black_fashion_minute);
    this.mSecondNeedle = BitmapFactory.decodeResource(this.mResources, R.drawable.black_fashion_second);
    this.mBatteryCharging = BitmapFactory.decodeResource(this.mResources, R.drawable.charging);
    this.mBatteryFull = BitmapFactory.decodeResource(this.mResources, R.drawable.full);
    this.mBatteryHigh = BitmapFactory.decodeResource(this.mResources, R.drawable.high);
    this.mBatteryLow = BitmapFactory.decodeResource(this.mResources, R.drawable.low);
    this.mBatteryMiddle = BitmapFactory.decodeResource(this.mResources, R.drawable.middle);
    this.mBatteryWaring = BitmapFactory.decodeResource(this.mResources, R.drawable.waring);
    this.mDimBg = BitmapFactory.decodeResource(this.mResources, R.drawable.black_fashion_dim_bg);
    this.mDimHourNeedle = BitmapFactory.decodeResource(this.mResources, R.drawable.black_fashion_dim_hour_needle);
    this.mDimMinuteNeedle = BitmapFactory.decodeResource(this.mResources, R.drawable.black_fashion_dim_minute_needle);
    this.mBatteryX = (this.pivotX - this.mBatteryFull.getWidth() / 2);
    this.mBatteryY = this.mCommonUtils.dip2px(164.0F);
  }

  /**
   * 白天画图层
   * @param canvas
     */
  private void doDayDraw(Canvas canvas,String DayOrNight){
      Profile.Section e_layer=null;  //异常的时候用的
      int i=0;
      try{
          for (Profile.Section layer:layers){
              e_layer = layer;
              i = i+1;  //第几个图层
              if (!layer.get("Show").contains(DayOrNight)){
                  continue;  //如果不是白天的图层就跳过
              }
              canvas.save();
              String type = layer.get("Type");
              float PosX = Float.parseFloat(layer.get("PosX"));
              float PosY = Float.parseFloat(layer.get("PosY"));
              int frame = 1;  //每秒帧数
              String speed = layer.get("Speed");  //自转速度
              if (speed!=null){
                  frame = Integer.parseInt(speed);
              }
              if (frame>60){//帧不能超过60
                  frame = 60;
              }

              int RVLT_frame=1;  //每秒帧数(公转)
              String RVLT_speed = layer.get("RVLT_Speed");  //公转速度
              if (RVLT_speed!=null){
                  RVLT_frame = Integer.parseInt(RVLT_speed);
              }
              if (RVLT_frame>60){//帧不能超过60
                  RVLT_frame = 60;
              }

              if (RVLT_frame>frame){
                  frameTop = RVLT_frame;
              }else{
                  frameTop = frame;
              }

              //这个先把它去掉吧。
              if (frameTop<15){
                  frameTop = 15;
              }

              int spinAngle = 0;  //每次旋转角度或范围
              String s_SpinAngle = layer.get("SpinAngle");
              if (s_SpinAngle!=null)
                  spinAngle = Integer.parseInt(s_SpinAngle);
              if (spinAngle>360)  //角度不能超过360度或-360度
                  spinAngle = 360;
              if (spinAngle<-360)
                  spinAngle = -360;

              int RVLT_spinAngle = 0;  //每次旋转角度或范围(公转)
              String RVLT_s_SpinAngle = layer.get("RVLT_SpinAngle");
              if (RVLT_s_SpinAngle!=null)
                  RVLT_spinAngle = Integer.parseInt(RVLT_s_SpinAngle);
              if (RVLT_spinAngle>360)  //角度不能超过360度或-360度
                  RVLT_spinAngle = 360;
              if (RVLT_spinAngle<-360)
                  RVLT_spinAngle = -360;

              //文字对齐方式，或者指针的对齐方式
              String align = layer.get("Align");
              if (align==null)
                  align="left";
              if (type.equals("text")){
                  //文字层
                  String text = layer.get("Content");
                  if (text.contains("{Battery}")){
                      //电量
                      text = text.replace("{Battery}",showBattery100Level+"");
                  }else if (text.contains("{Step}")){
                      //步数
                      text = text.replace("{Step}",mStep+"");
                  }else if (text.contains("{Weather.temp}")){
                      //温度
                      text = text.replace("{Weather.temp}",mTemperature+"");
                  }else if (text.contains("{Weather.desc}")){
                      //天气描述
                      text = text.replace("{Weather.desc}",mWeatherDesc+"");
                  }else if (text.contains("{Week.Cn}")){
                      //星期.中文
                      text = text.replace("{Week.Cn}",this.mCommonUtils.getDayNameOfWeek());
                  }else if (text.contains("{Week.En}")){
                      //星期.英文
                      text = text.replace("{Week.En}",this.mCommonUtils.getDayNameOfWeekEn());
                  }else if (text.contains("{Week.No}")){
                      //星期.数字
                      text = text.replace("{Week.No}",this.mCommonUtils.getDayNameOfWeekNo());
                  }else if (text.contains("{Month.Cn}")){
                      //月份.中文
                      text = text.replace("{Month.Cn}",this.mCommonUtils.getMonthChineseName());
                  }else if (text.contains("{Month.En}")){
                      //月份.英文
                      text = text.replace("{Month.En}",this.mCommonUtils.getMonthName());
                  }else if (text.contains("{Month.No}")){
                      //月份.数字
                      text = text.replace("{Month.No}",this.mCommonUtils.getMonthNo());
                  }else if(text.contains("{DaysMatter}")){
                      //倒数日
                      String s_date = layer.get("Date");
                      if (s_date==null){
                          return;  //空的就不显示了
                      }
                      if (s_date.length()==2){  //dd
                          Calendar setCal = Calendar.getInstance();
                          setCal.set(Calendar.DAY_OF_MONTH,Integer.parseInt(s_date));
                          Calendar cal = Calendar.getInstance();
                          if (setCal.get(Calendar.DAY_OF_MONTH)<cal.get(Calendar.DAY_OF_MONTH)){
                              //如果倒数日到期了
                              setCal.add(Calendar.MONTH,1);  //跳到下个月
                          }
                          long lDay = setCal.getTimeInMillis()-cal.getTimeInMillis();
                          long days = lDay/(1000*3600*24);
                          if (days==0&&lDay>86000000)   //误差校准
                              days=1;
                          text = text.replace("{DaysMatter}",days+"");
                      }else if (s_date.length()==5){   //MM-dd
                          Calendar setCal = Calendar.getInstance();
                          setCal.set(Calendar.MONTH,Integer.parseInt(s_date.split("-")[0])-1);  //月份是从0开始算起
                          setCal.set(Calendar.DAY_OF_MONTH,Integer.parseInt(s_date.split("-")[1]));
                          Calendar cal = Calendar.getInstance();
                          if (setCal.get(Calendar.DAY_OF_YEAR)<cal.get(Calendar.DAY_OF_YEAR)){
                              //如果倒数日到期了
                              setCal.add(Calendar.YEAR,1);  //跳到下一年
                          }
                          long lDay = setCal.getTimeInMillis()-cal.getTimeInMillis();
                          long days = lDay/(1000*3600*24);
                          if (days==0&&lDay>86000000)   //误差校准
                              days=1;
                          text = text.replace("{DaysMatter}",days+"");
                      }else if (s_date.length()==10){  //yyyy-MM-dd
                          Calendar setCal = Calendar.getInstance();
                          setCal.set(Calendar.YEAR,Integer.parseInt(s_date.split("-")[0]));
                          setCal.set(Calendar.MONTH,Integer.parseInt(s_date.split("-")[1])-1);  //月份是从0开始算起
                          setCal.set(Calendar.DAY_OF_MONTH,Integer.parseInt(s_date.split("-")[2]));
                          Calendar cal = Calendar.getInstance();
                          if (setCal.getTimeInMillis()<cal.getTimeInMillis()){
                              //如果倒数日到期了
                              return;  //直接不显示了
                          }
                          long lDay = setCal.getTimeInMillis()-cal.getTimeInMillis();
                          long days = lDay/(1000*3600*24);
                          if (days==0&&lDay>86000000)   //误差校准
                              days=1;
                          text = text.replace("{DaysMatter}",days+"");
                      }else{
                          return;  //格式不正确
                      }
                  }else if (text.contains("{StopWatch}")){
                      //计时器,文字型的就固定为60分钟的量吧,格式固定为mm:ss:ms
                      String s_format = layer.get("Format");
                      if (s_format==null)
                          s_format = "{60m}:{00s}:{ms}";  //默认等于60分
                      int minute=-1;
                      int second=-1;
                      if(s_format.contains("m}")){
                          String temp = s_format.substring(0,s_format.indexOf("m}"));
                          temp = temp.substring(temp.lastIndexOf("{")+1,temp.length());
                          minute = Integer.parseInt(temp);
                      }else if(s_format.contains("s}")){
                          String temp = s_format.substring(0,s_format.indexOf("s}"));
                          temp = temp.substring(temp.lastIndexOf("{")+1,temp.length());
                          second = Integer.parseInt(temp);
                      }
                      StopWatch stopWatch;
                      //联动-关联同一个计时器
                      String s_refId=layer.get("RefId");
                      if (s_refId!=null){
                          if (stopWatches.containsKey("RefId"+s_refId)){
                              stopWatch = stopWatches.get("RefId"+s_refId);
                              if (second!=-1){
                                  stopWatch.setSecond(second);
                              }
                              if (minute!=-1){
                                  stopWatch.setMinute(minute);
                              }
                          }else{
                              stopWatch = new StopWatch(minute==-1?0:minute,second==-1?0:second);
                              stopWatches.put("RefId"+s_refId,stopWatch);
                          }
                      }else{
                          if (stopWatches.containsKey("layer_"+i)){
                              stopWatch = stopWatches.get("layer_"+i);
                          }else{
                              stopWatch = new StopWatch(minute==-1?0:minute,second==-1?0:second);
                              stopWatches.put("layer_"+i,stopWatch);
                          }
                      }
                      text = text.replace("{StopWatch}",stopWatch.getTimeText(s_format));
                      //点击的情况
                      String touch = layer.get("Touch");  //默认显示情况
                      boolean swWork = true;  //计时器是否响应点击事件
                      if (touch!=null&&touch.equals("show")){
                          if (pics_hide.contains(i+"")){
                              swWork = false;
                          }
                      }else if (touch!=null&&touch.equals("hide")){
                          if (!pics_hide.contains(i+"")){
                              swWork = false;
                          }
                      }
                      //取点击范围吧
                      Rect rect = new Rect();
                      this.mPaint.getTextBounds(text,0,text.length(),rect);
                      int offset = 10; //默认加个10吧
                      String s_touchTime = layer.get("TouchTime");
                      int i_touchTime = 1;
                      if (s_touchTime!=null){
                          i_touchTime = Integer.parseInt(s_touchTime);
                      }
                      if (swWork&&isTouch&&touchTime==i_touchTime){
                          int trX = (int)PosX-offset;
                          int trY = (int)PosY-offset;
                          int trW = rect.width()+offset*2;
                          int trH = rect.height()+offset*2;
                          String touchRange = layer.get("TouchRange");  //可以自定义位置
                          if (touchRange!=null){
                              String[] touchRect = touchRange.split(",");
                              trX = Integer.parseInt(touchRect[0]);
                              trY = Integer.parseInt(touchRect[1]);
                              trW = Integer.parseInt(touchRect[2]);
                              trH = Integer.parseInt(touchRect[3]);
                          }
                          if (touchX>=trX&&touchX<=trX+trW
                                  &&touchY>=trY&&touchY<=trY+trH){
                              //这里点击成功了
                              if (stopWatch.getState()==0)
                                  stopWatch.start();
                              else if (stopWatch.getState()==1)
                                  stopWatch.stop();
                              else if (stopWatch.getState()==2)
                                  stopWatch.reset();
                          }
                      }
                  }else if(text.contains("{")&&text.contains("}")){
                      //日期格式
                      Date now = new Date();
                      //日期的加减
                      if (text.contains("-(")||text.contains("+(")){
                          now = TextTools.dateCompute(text,now);
                          //去掉+和-后面的内容
                          if (text.contains("-"))
                              text = text.substring(0,text.indexOf("-"));
                          else if (text.contains("+"))
                              text = text.substring(0,text.indexOf("+"));
                      }
                      String format = text.substring(text.indexOf("{")+1,text.indexOf("}"));
                      String date = new SimpleDateFormat(format,Locale.CHINA).format(now);
                      text = text.replace("{"+format+"}",date);
                  }
                  //字体
                  String font = layer.get("Font");
                  if (!fonts.containsKey(font)){
                      //如果字体还没有加载到内存中，就加载一下
                      fonts.put(font,Typeface.createFromFile(sdCard+"/zylWatchFace/"+cName+"/"+font));
                  }
                  this.mPaint.setTypeface(fonts.get(font));
                  this.mPaint.setTextSize(Float.parseFloat(layer.get("Size")));  //字体大小
                  this.mPaint.setColor(Color.parseColor(layer.get("Color")));  //字体颜色
                  //对齐方式
                  if (align.equals("center")){
                      PosX = PosX - (this.mPaint.measureText(text)/2);
                  }else if (align.equals("right")){
                      PosX = PosX - this.mPaint.measureText(text);
                  }
                  //旋转角度
                  canvas.translate(PosX,PosY);
                  canvas.rotate(spinAngle);  //旋转的角度
                  canvas.translate(-PosX,-PosY);
                  //这里判断是否显示吧
                  boolean canDraw = true;
                  String touch = layer.get("Touch");
                  String touchRange = layer.get("TouchRange");
                  String s_touchTime = layer.get("TouchTime");
                  String s_touchApp = layer.get("TouchApp");
                  String s_touchAppRange = layer.get("TouchAppRange");
                  int i_touchTime = 1;
                  if (s_touchTime!=null){
                      i_touchTime = Integer.parseInt(s_touchTime);
                  }
                  if (touch!=null&&touchRange!=null&&isTouch&&touchTime==i_touchTime){
                      String[] touchRect = touchRange.split(",");
                      int trX = Integer.parseInt(touchRect[0]);
                      int trY = Integer.parseInt(touchRect[1]);
                      int trW = Integer.parseInt(touchRect[2]);
                      int trH = Integer.parseInt(touchRect[3]);
                      if (touchX>=trX&&touchX<=trX+trW
                              &&touchY>=trY&&touchY<=trY+trH){
                          //如果正好在图片所在范围，那么就触发一下显示/隐藏吧
                          if (touch.equals("show")){
                              if (!pics_hide.contains(i+"")){
                                  pics_hide.add(i+"");
                              }else{
                                  pics_hide.remove(i+"");
                              }
                          }else if (touch.equals("hide")){
                              if (pics_hide.contains(i+"")){
                                  pics_hide.remove(i+"");
                              }else{
                                  pics_hide.add(i+"");
                              }
                          }
                      }
                      //app点击范围分开来吧，默认跟着TouchRange
                        if (s_touchAppRange!=null){
                            touchRect = s_touchAppRange.split(",");
                            trX = Integer.parseInt(touchRect[0]);
                            trY = Integer.parseInt(touchRect[1]);
                            trW = Integer.parseInt(touchRect[2]);
                            trH = Integer.parseInt(touchRect[3]);
                        }
                      if (touchX>=trX&&touchX<=trX+trW
                              &&touchY>=trY&&touchY<=trY+trH){
                          //如果正好在图片所在范围，那么就触发一下显示/隐藏吧
                          if (touch.equals("show")){
                              if (!pics_hide.contains(i+"")){
//                                  pics_hide.add(i+"");
                                  //这里显示的时候点击成功了,调用app
                                  if (s_touchApp!=null)
                                      AppTools.startApp(mContext,s_touchApp);
                              }else{
//                                  pics_hide.remove(i+"");
                              }
                          }else if (touch.equals("hide")){
                              if (pics_hide.contains(i+"")){
//                                  pics_hide.remove(i+"");
                              }else{
//                                  pics_hide.add(i+"");
                                  //这里显示的时候点击成功了,调用app
                                  if (s_touchApp!=null)
                                      AppTools.startApp(mContext,s_touchApp);
                              }
                          }else if (touch.equals("all")){  //不做显示隐藏触发
                              //这里是指显示的时候点击成功了
                              if (s_touchApp!=null)
                                  AppTools.startApp(mContext,s_touchApp);
                          }
                      }
                  }
                  //没有点击的情况处理
                  if (touch!=null&&touch.equals("show")){
                      if (pics_hide.contains(i+"")){
                          canDraw = false;
                      }
                  }else if (touch!=null&&touch.equals("hide")){
                      if (!pics_hide.contains(i+"")){
                          canDraw = false;
                      }
                  }
                  if (canDraw)
                      canvas.drawText(text, PosX, PosY, this.mPaint);
              }else if (type.equals("image")){
                  boolean canDraw = true;
                  String Content = layer.get("Content");
                  //图片层
                  String pic = "";
                  if (Content.contains("{Static}")){
                      pic = layer.get("Pic");
                  }else if (Content.contains("{HourHand}")){
                      String[] pics = layer.get("Pic").split(",");
                      String picRight=null;
                      String picShadow=null;
                      if (pics.length==2){
                          //这个是有阴影
                          pic = pics[0];   //指针
                          picShadow = pics[1];  //阴影
                      }else if(pics.length>=3){
                          //这个是有阴影，指针还有左右两面
                          pic = pics[0];  //左面
                          picRight = pics[1];  //右面
                          picShadow = pics[2];  //阴影
                      }else{
                          pic = layer.get("Pic");
                      }
                      if (!this.pics.containsKey(pic)){
                          //内存中没有图片的时候，先加载一下图片吧
                          this.pics.put(pic,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+pic));
                      }
                      float newX = PosX+this.pics.get(pic).getWidth()/2;
                      float newY = PosY+this.pics.get(pic).getHeight()/2;
                      canvas.translate(newX,newY);
                      float angle=this.mCommonUtils.getHourSweepAngle() % 360;
                      canvas.rotate(angle);
                      canvas.translate(-newX,-newY);
                      //看看这里准备画一下阴影试一下
                      if (picShadow!=null){
                          int sPx = 10;  //阴影长(三角形斜边),默认10吧
                          String c_sPx = layer.get("Shadow");  //阴影长度
                          if (c_sPx!=null)
                              sPx = Integer.parseInt(c_sPx);
                          int sunAngle = 0;  //太阳照射角度
                          String s_sunAngle = layer.get("SunAngle");
                          if (s_sunAngle!=null)
                              sunAngle = Integer.parseInt(s_sunAngle);
                          double sCon =Math.toRadians(angle-sunAngle);
                          float sX = (float)(Math.sin(sCon)*sPx);  //x坐标
                          float sY = (float)(Math.cos(sCon)*sPx);  //y坐标
                          if (!this.pics.containsKey(picShadow)){
                              //内存中没有图片的时候，先加载一下图片吧
                              this.pics.put(picShadow,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+picShadow));
                          }
                          canvas.drawBitmap(this.pics.get(picShadow),PosX+sX, PosY+sY, null);
                          //这里处理指针的左右阴影
                          if(picRight!=null){
                              if (sunAngle<0){
                                  if(angle>360+sunAngle&&angle<=360||angle>=0&&angle<360+sunAngle-180)
                                      pic = picRight;  //右阴影
                              }else{
                                  if (angle>sunAngle&&angle<sunAngle+180)
                                      pic = picRight;  //右阴影
                              }
                          }
                      }
                  }else if (Content.contains("{HourHand.24}")){
                      String[] pics = layer.get("Pic").split(",");
                      String picRight=null;
                      String picShadow=null;
                      if (pics.length==2){
                          //这个是有阴影
                          pic = pics[0];   //指针
                          picShadow = pics[1];  //阴影
                      }else if(pics.length>=3){
                          //这个是有阴影，指针还有左右两面
                          pic = pics[0];  //左面
                          picRight = pics[1];  //右面
                          picShadow = pics[2];  //阴影
                      }else{
                          pic = layer.get("Pic");
                      }
                      if (!this.pics.containsKey(pic)){
                          //内存中没有图片的时候，先加载一下图片吧
                          this.pics.put(pic,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+pic));
                      }
                      float newX = PosX+this.pics.get(pic).getWidth()/2;
                      float newY = PosY+this.pics.get(pic).getHeight()/2;
                      canvas.translate(newX,newY);
                      float angle=this.mCommonUtils.getHour24SweepAngle() % 360;
                      canvas.rotate(angle);
                      canvas.translate(-newX,-newY);
                      //看看这里准备画一下阴影试一下
                      if (picShadow!=null){
                          int sPx = 10;  //阴影长(三角形斜边),默认10吧
                          String c_sPx = layer.get("Shadow");  //阴影长度
                          if (c_sPx!=null)
                              sPx = Integer.parseInt(c_sPx);
                          int sunAngle = 0;  //太阳照射角度
                          String s_sunAngle = layer.get("SunAngle");
                          if (s_sunAngle!=null)
                              sunAngle = Integer.parseInt(s_sunAngle);
                          double sCon =Math.toRadians(angle-sunAngle);
                          float sX = (float)(Math.sin(sCon)*sPx);  //x坐标
                          float sY = (float)(Math.cos(sCon)*sPx);  //y坐标
                          if (!this.pics.containsKey(picShadow)){
                              //内存中没有图片的时候，先加载一下图片吧
                              this.pics.put(picShadow,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+picShadow));
                          }
                          canvas.drawBitmap(this.pics.get(picShadow),PosX+sX, PosY+sY, null);
                          //这里处理指针的左右阴影
                          if(picRight!=null){
                              if (sunAngle<0){
                                  if(angle>360+sunAngle&&angle<=360||angle>=0&&angle<360+sunAngle-180)
                                      pic = picRight;  //右阴影
                              }else{
                                  if (angle>sunAngle&&angle<sunAngle+180)
                                      pic = picRight;  //右阴影
                              }
                          }
                      }
                  }else if (Content.contains("{MinuteHand}")){
                      String[] pics = layer.get("Pic").split(",");
                      String picRight=null;
                      String picShadow=null;
                      if (pics.length==2){
                          //这个是有阴影
                          pic = pics[0];   //指针
                          picShadow = pics[1];  //阴影
                      }else if(pics.length>=3){
                          //这个是有阴影，指针还有左右两面
                          pic = pics[0];  //左面
                          picRight = pics[1];  //右面
                          picShadow = pics[2];  //阴影
                      }else{
                          pic = layer.get("Pic");
                      }
                      if (!this.pics.containsKey(pic)){
                          //内存中没有图片的时候，先加载一下图片吧
                          this.pics.put(pic,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+pic));
                      }
                      float newX = PosX+this.pics.get(pic).getWidth()/2;
                      float newY = PosY+this.pics.get(pic).getHeight()/2;
                      canvas.translate(newX,newY);
                      float angle=this.mCommonUtils.getMinuteSweepAngle() % 360;
                      canvas.rotate(angle);
                      canvas.translate(-newX,-newY);
                      //看看这里准备画一下阴影试一下
                      if (picShadow!=null){
                          int sPx = 10;  //阴影长(三角形斜边),默认10吧
                          String c_sPx = layer.get("Shadow");  //阴影长度
                          if (c_sPx!=null)
                              sPx = Integer.parseInt(c_sPx);
                          int sunAngle = 0;  //太阳照射角度
                          String s_sunAngle = layer.get("SunAngle");
                          if (s_sunAngle!=null)
                              sunAngle = Integer.parseInt(s_sunAngle);
                          double sCon =Math.toRadians(angle-sunAngle);
                          float sX = (float)(Math.sin(sCon)*sPx);  //x坐标
                          float sY = (float)(Math.cos(sCon)*sPx);  //y坐标
                          if (!this.pics.containsKey(picShadow)){
                              //内存中没有图片的时候，先加载一下图片吧
                              this.pics.put(picShadow,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+picShadow));
                          }
                          canvas.drawBitmap(this.pics.get(picShadow),PosX+sX, PosY+sY, null);
                          //这里处理指针的左右阴影
                          if(picRight!=null){
                              if (sunAngle<0){
                                  if(angle>360+sunAngle&&angle<=360||angle>=0&&angle<360+sunAngle-180)
                                      pic = picRight;  //右阴影
                              }else{
                                  if (angle>sunAngle&&angle<sunAngle+180)
                                      pic = picRight;  //右阴影
                              }
                          }
                      }
                  }else if (Content.contains("{SecondHand}")){
                      String[] pics = layer.get("Pic").split(",");
                      String picRight=null;
                      String picShadow=null;
                      if (pics.length==2){
                          //这个是有阴影
                          pic = pics[0];   //指针
                          picShadow = pics[1];  //阴影
                      }else if(pics.length>=3){
                          //这个是有阴影，指针还有左右两面
                          pic = pics[0];  //左面
                          picRight = pics[1];  //右面
                          picShadow = pics[2];  //阴影
                      }else{
                          pic = layer.get("Pic");
                      }
                      if (!this.pics.containsKey(pic)){
                          //内存中没有图片的时候，先加载一下图片吧
                          this.pics.put(pic,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+pic));
                      }
                      float newX = PosX+this.pics.get(pic).getWidth()/2;
                      float newY = PosY+this.pics.get(pic).getHeight()/2;
                      canvas.translate(newX,newY);
                      float angle;
                      if (SecondType.equals("run")){
                          angle = this.mCommonUtils.getSecondSweepAngle() % 360;
                      }else{
                          angle = this.mCommonUtils.getSecondWalkAngle() % 360;
                      }
                      canvas.rotate(angle);
                      canvas.translate(-newX,-newY);
                      //看看这里准备画一下阴影试一下
                      if (picShadow!=null){
                          int sPx = 10;  //阴影长(三角形斜边),默认10吧
                          String c_sPx = layer.get("Shadow");  //阴影长度
                          if (c_sPx!=null)
                              sPx = Integer.parseInt(c_sPx);
                          int sunAngle = 0;  //太阳照射角度
                          String s_sunAngle = layer.get("SunAngle");
                          if (s_sunAngle!=null)
                              sunAngle = Integer.parseInt(s_sunAngle);
                          double sCon =Math.toRadians(angle-sunAngle);
                          float sX = (float)(Math.sin(sCon)*sPx);  //x坐标
                          float sY = (float)(Math.cos(sCon)*sPx);  //y坐标
                          if (!this.pics.containsKey(picShadow)){
                              //内存中没有图片的时候，先加载一下图片吧
                              this.pics.put(picShadow,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+picShadow));
                          }
                          canvas.drawBitmap(this.pics.get(picShadow),PosX+sX, PosY+sY, null);
                          //这里处理指针的左右阴影
                          if(picRight!=null){
                              if (sunAngle<0){
                                  if(angle>360+sunAngle&&angle<=360||angle>=0&&angle<360+sunAngle-180)
                                      pic = picRight;  //右阴影
                              }else{
                                  if (angle>sunAngle&&angle<sunAngle+180)
                                      pic = picRight;  //右阴影
                              }
                          }
                      }
                  }else if (Content.contains("{Switch}")){  //切换
                      String[] pics = layer.get("Pic").split(",");
                      //1帧/秒试一下先
//                      long secondMills = this.mCommonUtils.getSecondsNow()*1000+this.mCommonUtils.getMillsNow();
//                      int y = (int) ((secondMills/(this.INTERVAL_MILLIS*(frameTop-frame+1))) % pics.length);
                      boolean needJump = false;
                      int jumpTop = 0;
                      int jumpIndex = 0;
                      if (frame<frameTop){
                          jumpTop = frameTop - frame;
                          if (this.framesjump.containsKey(i+"")){
                              jumpIndex = this.framesjump.get(i+"");
                          }
                          if (jumpIndex<jumpTop){
                              this.framesjump.put(i+"",jumpIndex+1);
                              needJump = true;
                          }else if (jumpIndex>=jumpTop){
                              this.framesjump.remove(i+"");
                          }
                      }

                      int z_index = 0;
                      if (this.switchs.containsKey(i+"")){
                          z_index = this.switchs.get(i+"");
                      }
                      if (z_index>=pics.length){
                          z_index = 0;
                      }
                      pic = pics[z_index];
                      if(!needJump) {
                          z_index++;
                      }
                      this.switchs.put(i+"",z_index);
//                      if(z_index == 0){
//                          pic = pics[pics.length-1];
//                      }else{
//                          pic = pics[z_index-1];
//                      }
                  }else if (Content.contains("{Spin}")){  //旋转
                      pic = layer.get("Pic");

                      //这里准备加公转吧
                      if (layer.get("RVLT_X")!=null&&layer.get("RVLT_Y")!=null){
                          if (RVLT_spinAngle==0)
                              RVLT_spinAngle = 1;
                          boolean RVLT_needJump = false;
                          int RVLT_jumpTop = 0;
                          int RVLT_jumpIndex = 0;
                          if (RVLT_frame<frameTop){
                              RVLT_jumpTop = frameTop / RVLT_frame;  //跳过几帧要用除
                              if (this.RVLT_framesjump.containsKey(i+"")){
                                  RVLT_jumpIndex = this.RVLT_framesjump.get(i+"");
                              }
                              if (RVLT_jumpIndex<RVLT_jumpTop){
                                  this.RVLT_framesjump.put(i+"",RVLT_jumpIndex+1);
                                  RVLT_needJump = true;
                              }else if (RVLT_jumpIndex>=RVLT_jumpTop){
                                  this.RVLT_framesjump.remove(i+"");
                              }
                          }
                          float RVLT_z_spinAngle = 0;
                          if (this.RVLT_spins.containsKey(i+"")){
                              RVLT_z_spinAngle = this.RVLT_spins.get(i+"");
                          }
                          if(!RVLT_needJump){
                              RVLT_z_spinAngle = RVLT_z_spinAngle + RVLT_spinAngle;
                          }
                          if (RVLT_z_spinAngle>360||RVLT_z_spinAngle<-360){
                              RVLT_z_spinAngle = RVLT_z_spinAngle % 360;
                          }
                          this.RVLT_spins.put(i+"",RVLT_z_spinAngle);
                          if (!pics.containsKey(pic)){
                              //内存中没有图片的时候，先加载一下图片吧
                              pics.put(pic,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+pic));
                          }
                          float RVLT_X = Float.parseFloat(layer.get("RVLT_X"));
                          float RVLT_Y = Float.parseFloat(layer.get("RVLT_Y"));
                          canvas.translate(RVLT_X,RVLT_Y);
                          canvas.rotate(RVLT_z_spinAngle);  //旋转的角度
                          canvas.translate(-RVLT_X,-RVLT_Y);
//                          canvas.drawBitmap(pics.get(pic),RVLT_X, RVLT_Y, null);  //这里直接画一下试试看吧
                      }

                      if (spinAngle==0)  //如果旋转角度是0的话，默认就用1吧
                          spinAngle = 1;
//                      long secondMills = this.mCommonUtils.getSecondsNow()*1000+this.mCommonUtils.getMillsNow();
//                      float y = (int) ((secondMills/(this.INTERVAL_MILLIS*(frameTop-frame+1))) % (360/Math.abs(spinAngle)));
                      boolean needJump = false;
                      int jumpTop = 0;
                      int jumpIndex = 0;
                      if (frame<frameTop){
                          jumpTop = frameTop / frame;  //跳过几帧要用除
                          if (this.framesjump.containsKey(i+"")){
                              jumpIndex = this.framesjump.get(i+"");
                          }
                          if (jumpIndex<jumpTop){
                              this.framesjump.put(i+"",jumpIndex+1);
                              needJump = true;
                          }else if (jumpIndex>=jumpTop){
                              this.framesjump.remove(i+"");
                          }
                      }


                      float z_spinAngle = 0;
                      if (this.spins.containsKey(i+"")){
                          z_spinAngle = this.spins.get(i+"");
                      }
                      if(!needJump){
                          z_spinAngle = z_spinAngle + spinAngle;
                      }
                      if (z_spinAngle>360||z_spinAngle<-360){
                          z_spinAngle = z_spinAngle % 360;
                      }
                      this.spins.put(i+"",z_spinAngle);
                      if (!pics.containsKey(pic)){
                          //内存中没有图片的时候，先加载一下图片吧
                          pics.put(pic,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+pic));
                      }
                      float newX = PosX+pics.get(pic).getWidth()/2;
                      float newY = PosY+pics.get(pic).getHeight()/2;
                      canvas.translate(newX,newY);
                      canvas.rotate(z_spinAngle);  //旋转的角度
                      canvas.translate(-newX,-newY);
                  }else if (Content.contains("{Week}")){
                      String[] pics = layer.get("Pic").split(",");
                      if(Integer.parseInt(this.mCommonUtils.getDayNameOfWeekNo())>pics.length){
                          pic = pics[pics.length-1];
                      }else{
                          pic = pics[Integer.parseInt(this.mCommonUtils.getDayNameOfWeekNo())-1];
                      }
                      //有切换的图片
                      if (pic.contains("|")){
                          pics = pic.split("\\|");
                          boolean needJump = false;
                          int jumpTop = 0;
                          int jumpIndex = 0;
                          if (frame<frameTop){
                              jumpTop = frameTop - frame;
                              if (this.framesjump.containsKey(i+"")){
                                  jumpIndex = this.framesjump.get(i+"");
                              }
                              if (jumpIndex<jumpTop){
                                  this.framesjump.put(i+"",jumpIndex+1);
                                  needJump = true;
                              }else if (jumpIndex>=jumpTop){
                                  this.framesjump.remove(i+"");
                              }
                          }

                          int z_index = 0;
                          if (this.switchs.containsKey(i+"")){
                              z_index = this.switchs.get(i+"");
                          }
                          if (z_index>=pics.length){
                              z_index = 0;
                          }
                          pic = pics[z_index];
                          if(!needJump) {
                              z_index++;
                          }
                          this.switchs.put(i+"",z_index);
//                          //1帧/秒试一下先
//                          long secondMills = this.mCommonUtils.getSecondsNow()*1000+this.mCommonUtils.getMillsNow();
//                          int y = (int) ((secondMills/(this.INTERVAL_MILLIS*(frameTop-frame+1))) % pics.length);
//                          if(y == 0){
//                              pic = pics[pics.length-1];
//                          }else{
//                              pic = pics[y-1];
//                          }
                      }
                  }else if (Content.contains("{Week.Spin}")){
                      String[] pics = layer.get("Pic").split(",");
                      String picRight=null;
                      String picShadow=null;
                      if (pics.length==2){
                          //这个是有阴影
                          pic = pics[0];   //指针
                          picShadow = pics[1];  //阴影
                      }else if(pics.length>=3){
                          //这个是有阴影，指针还有左右两面
                          pic = pics[0];  //左面
                          picRight = pics[1];  //右面
                          picShadow = pics[2];  //阴影
                      }else{
                          pic = layer.get("Pic");
                      }
                      float angle = spinAngle/7.0f;  //7天
                      float offset=0;
                      if (align.equals("center")){
                          offset = -angle/2;
                      }else if (align.equals("left")){
                          offset = -angle;
                      }
                      if (!this.pics.containsKey(pic)){
                          //内存中没有图片的时候，先加载一下图片吧
                          this.pics.put(pic,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+pic));
                      }
                      float newX = PosX+this.pics.get(pic).getWidth()/2;
                      float newY = PosY+this.pics.get(pic).getHeight()/2;
                      canvas.translate(newX,newY);
                      canvas.rotate(Integer.parseInt(this.mCommonUtils.getDayNameOfWeekNo())*angle+offset);  //旋转的角度
                      canvas.translate(-newX,-newY);
                      //看看这里准备画一下阴影试一下
                      if (picShadow!=null){
                          int sPx = 10;  //阴影长(三角形斜边),默认10吧
                          String c_sPx = layer.get("Shadow");  //阴影长度
                          if (c_sPx!=null)
                              sPx = Integer.parseInt(c_sPx);
                          int sunAngle = 0;  //太阳照射角度
                          String s_sunAngle = layer.get("SunAngle");
                          if (s_sunAngle!=null)
                              sunAngle = Integer.parseInt(s_sunAngle);
                          double sCon =Math.toRadians(angle+offset-sunAngle);
                          float sX = (float)(Math.sin(sCon)*sPx);  //x坐标
                          float sY = (float)(Math.cos(sCon)*sPx);  //y坐标
                          if (!this.pics.containsKey(picShadow)){
                              //内存中没有图片的时候，先加载一下图片吧
                              this.pics.put(picShadow,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+picShadow));
                          }
                          canvas.drawBitmap(this.pics.get(picShadow),PosX+sX, PosY+sY, null);
                          //这里处理指针的左右阴影
                          if(picRight!=null){
                              if (sunAngle<0){
                                  if(angle+offset>360+sunAngle&&angle+offset<=360||angle+offset>=0&&angle+offset<360+sunAngle-180)
                                      pic = picRight;  //右阴影
                              }else{
                                  if (angle+offset>sunAngle&&angle+offset<sunAngle+180)
                                      pic = picRight;  //右阴影
                              }
                          }
                      }
                  }else if (Content.contains("{Month}")){
                      String[] pics = layer.get("Pic").split(",");
                      if(Integer.parseInt(this.mCommonUtils.getMonthNo())>pics.length){
                          pic = pics[pics.length-1];
                      }else{
                          pic = pics[Integer.parseInt(this.mCommonUtils.getMonthNo())-1];
                      }
                  }else if (Content.contains("{Month.Spin}")){
                      String[] pics = layer.get("Pic").split(",");
                      String picRight=null;
                      String picShadow=null;
                      if (pics.length==2){
                          //这个是有阴影
                          pic = pics[0];   //指针
                          picShadow = pics[1];  //阴影
                      }else if(pics.length>=3){
                          //这个是有阴影，指针还有左右两面
                          pic = pics[0];  //左面
                          picRight = pics[1];  //右面
                          picShadow = pics[2];  //阴影
                      }else{
                          pic = layer.get("Pic");
                      }
                      float angle = spinAngle/12.0f;  //12个月份
                      float offset=0;
                      if (align.equals("center")){
                          offset = -angle/2;
                      }else if (align.equals("left")){
                          offset = -angle;
                      }
                      if (!this.pics.containsKey(pic)){
                          //内存中没有图片的时候，先加载一下图片吧
                          this.pics.put(pic,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+pic));
                      }
                      float newX = PosX+this.pics.get(pic).getWidth()/2;
                      float newY = PosY+this.pics.get(pic).getHeight()/2;
                      canvas.translate(newX,newY);
                      canvas.rotate(Integer.parseInt(this.mCommonUtils.getMonthNo())*angle+offset);  //旋转的角度
                      canvas.translate(-newX,-newY);
                      //看看这里准备画一下阴影试一下
                      if (picShadow!=null){
                          int sPx = 10;  //阴影长(三角形斜边),默认10吧
                          String c_sPx = layer.get("Shadow");  //阴影长度
                          if (c_sPx!=null)
                              sPx = Integer.parseInt(c_sPx);
                          int sunAngle = 0;  //太阳照射角度
                          String s_sunAngle = layer.get("SunAngle");
                          if (s_sunAngle!=null)
                              sunAngle = Integer.parseInt(s_sunAngle);
                          double sCon =Math.toRadians(angle+offset-sunAngle);
                          float sX = (float)(Math.sin(sCon)*sPx);  //x坐标
                          float sY = (float)(Math.cos(sCon)*sPx);  //y坐标
                          if (!this.pics.containsKey(picShadow)){
                              //内存中没有图片的时候，先加载一下图片吧
                              this.pics.put(picShadow,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+picShadow));
                          }
                          canvas.drawBitmap(this.pics.get(picShadow),PosX+sX, PosY+sY, null);
                          //这里处理指针的左右阴影
                          if(picRight!=null){
                              if (sunAngle<0){
                                  if(angle+offset>360+sunAngle&&angle+offset<=360||angle+offset>=0&&angle+offset<360+sunAngle-180)
                                      pic = picRight;  //右阴影
                              }else{
                                  if (angle+offset>sunAngle&&angle+offset<sunAngle+180)
                                      pic = picRight;  //右阴影
                              }
                          }
                      }
                  }else if (Content.contains("{DayOfMonth}")){
                      String[] pics = layer.get("Pic").split(",");
                      if(Integer.parseInt(this.mCommonUtils.getDayOfMonth())>pics.length){
                          pic = pics[pics.length-1];
                      }else{
                          pic = pics[Integer.parseInt(this.mCommonUtils.getDayOfMonth())-1];
                      }
                  }else if (Content.contains("{DayOfMonth.Spin}")){
                      String[] pics = layer.get("Pic").split(",");
                      String picRight=null;
                      String picShadow=null;
                      if (pics.length==2){
                          //这个是有阴影
                          pic = pics[0];   //指针
                          picShadow = pics[1];  //阴影
                      }else if(pics.length>=3){
                          //这个是有阴影，指针还有左右两面
                          pic = pics[0];  //左面
                          picRight = pics[1];  //右面
                          picShadow = pics[2];  //阴影
                      }else{
                          pic = layer.get("Pic");
                      }
                      float angle = spinAngle/31.0f;  //31天每月份
                      float offset=0;
                      if (align.equals("center")){
                          offset = -angle/2;
                      }else if (align.equals("left")){
                          offset = -angle;
                      }
                      if (!this.pics.containsKey(pic)){
                          //内存中没有图片的时候，先加载一下图片吧
                          this.pics.put(pic,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+pic));
                      }
                      float newX = PosX+this.pics.get(pic).getWidth()/2;
                      float newY = PosY+this.pics.get(pic).getHeight()/2;
                      canvas.translate(newX,newY);
                      canvas.rotate(Integer.parseInt(this.mCommonUtils.getDayOfMonth())*angle+offset);  //旋转的角度
                      canvas.translate(-newX,-newY);
                      //看看这里准备画一下阴影试一下
                      if (picShadow!=null){
                          int sPx = 10;  //阴影长(三角形斜边),默认10吧
                          String c_sPx = layer.get("Shadow");  //阴影长度
                          if (c_sPx!=null)
                              sPx = Integer.parseInt(c_sPx);
                          int sunAngle = 0;  //太阳照射角度
                          String s_sunAngle = layer.get("SunAngle");
                          if (s_sunAngle!=null)
                              sunAngle = Integer.parseInt(s_sunAngle);
                          double sCon =Math.toRadians(angle+offset-sunAngle);
                          float sX = (float)(Math.sin(sCon)*sPx);  //x坐标
                          float sY = (float)(Math.cos(sCon)*sPx);  //y坐标
                          if (!this.pics.containsKey(picShadow)){
                              //内存中没有图片的时候，先加载一下图片吧
                              this.pics.put(picShadow,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+picShadow));
                          }
                          canvas.drawBitmap(this.pics.get(picShadow),PosX+sX, PosY+sY, null);
                          //这里处理指针的左右阴影
                          if(picRight!=null){
                              if (sunAngle<0){
                                  if(angle+offset>360+sunAngle&&angle+offset<=360||angle+offset>=0&&angle+offset<360+sunAngle-180)
                                      pic = picRight;  //右阴影
                              }else{
                                  if (angle+offset>sunAngle&&angle+offset<sunAngle+180)
                                      pic = picRight;  //右阴影
                              }
                          }
                      }
                  }else if (Content.contains("{DayOfLunarMonth}")){
                      //农历日期
                      LunarCalendar lc = new LunarCalendar(new Date());
                      Calendar cal = Calendar.getInstance();
                      cal.setTime(lc.getDate());
                      String[] pics = layer.get("Pic").split(",");
                      if(cal.get(Calendar.DAY_OF_MONTH)>pics.length){
                          pic = pics[pics.length-1];
                      }else{
                          pic = pics[cal.get(Calendar.DAY_OF_MONTH)-1];
                      }
                  }else if (Content.contains("{DayOfLunarMonth.Spin}")){
                      //农历日期旋转
                      LunarCalendar lc = new LunarCalendar(new Date());
                      Calendar cal = Calendar.getInstance();
                      cal.setTime(lc.getDate());
                      String[] pics = layer.get("Pic").split(",");
                      String picRight=null;
                      String picShadow=null;
                      if (pics.length==2){
                          //这个是有阴影
                          pic = pics[0];   //指针
                          picShadow = pics[1];  //阴影
                      }else if(pics.length>=3){
                          //这个是有阴影，指针还有左右两面
                          pic = pics[0];  //左面
                          picRight = pics[1];  //右面
                          picShadow = pics[2];  //阴影
                      }else{
                          pic = layer.get("Pic");
                      }
                      float angle = spinAngle/30.0f;  //31天每月份
                      float offset=0;
                      if (align.equals("center")){
                          offset = -angle/2;
                      }else if (align.equals("left")){
                          offset = -angle;
                      }
                      if (!this.pics.containsKey(pic)){
                          //内存中没有图片的时候，先加载一下图片吧
                          this.pics.put(pic,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+pic));
                      }
                      float newX = PosX+this.pics.get(pic).getWidth()/2;
                      float newY = PosY+this.pics.get(pic).getHeight()/2;
                      canvas.translate(newX,newY);
                      canvas.rotate(cal.get(Calendar.DAY_OF_MONTH)*angle+offset);  //旋转的角度
                      canvas.translate(-newX,-newY);
                      //看看这里准备画一下阴影试一下
                      if (picShadow!=null){
                          int sPx = 10;  //阴影长(三角形斜边),默认10吧
                          String c_sPx = layer.get("Shadow");  //阴影长度
                          if (c_sPx!=null)
                              sPx = Integer.parseInt(c_sPx);
                          int sunAngle = 0;  //太阳照射角度
                          String s_sunAngle = layer.get("SunAngle");
                          if (s_sunAngle!=null)
                              sunAngle = Integer.parseInt(s_sunAngle);
                          double sCon =Math.toRadians(angle+offset-sunAngle);
                          float sX = (float)(Math.sin(sCon)*sPx);  //x坐标
                          float sY = (float)(Math.cos(sCon)*sPx);  //y坐标
                          if (!this.pics.containsKey(picShadow)){
                              //内存中没有图片的时候，先加载一下图片吧
                              this.pics.put(picShadow,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+picShadow));
                          }
                          canvas.drawBitmap(this.pics.get(picShadow),PosX+sX, PosY+sY, null);
                          //这里处理指针的左右阴影
                          if(picRight!=null){
                              if (sunAngle<0){
                                  if(angle+offset>360+sunAngle&&angle+offset<=360||angle+offset>=0&&angle+offset<360+sunAngle-180)
                                      pic = picRight;  //右阴影
                              }else{
                                  if (angle+offset>sunAngle&&angle+offset<sunAngle+180)
                                      pic = picRight;  //右阴影
                              }
                          }
                      }
                  }else if (Content.contains("{Battery}")){  //电量图片
                      String[] pics = layer.get("Pic").split(",");
                      if (showBattery100Level>=100){
                          pic = pics[pics.length-1];
                      }else{
                          pic = pics[showBattery100Level/(100/pics.length)];
                      }
                  }else if (Content.contains("{Battery.Spin}")){
                      String[] pics = layer.get("Pic").split(",");
                      String picRight=null;
                      String picShadow=null;
                      if (pics.length==2){
                          //这个是有阴影
                          pic = pics[0];   //指针
                          picShadow = pics[1];  //阴影
                      }else if(pics.length>=3){
                          //这个是有阴影，指针还有左右两面
                          pic = pics[0];  //左面
                          picRight = pics[1];  //右面
                          picShadow = pics[2];  //阴影
                      }else{
                          pic = layer.get("Pic");
                      }
                      float angle = spinAngle/100.0f;  //100的电量
                      float offset=0;
                      if (align.equals("center")){
                          offset = -angle/2;
                      }else if (align.equals("left")){
                          offset = -angle;
                      }
                      if (!this.pics.containsKey(pic)){
                          //内存中没有图片的时候，先加载一下图片吧
                          this.pics.put(pic,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+pic));
                      }
                      float newX = PosX+this.pics.get(pic).getWidth()/2;
                      float newY = PosY+this.pics.get(pic).getHeight()/2;
                      canvas.translate(newX,newY);
                      canvas.rotate(showBattery100Level*angle+offset);  //旋转的角度
                      canvas.translate(-newX,-newY);
                      //看看这里准备画一下阴影试一下
                      if (picShadow!=null){
                          int sPx = 10;  //阴影长(三角形斜边),默认10吧
                          String c_sPx = layer.get("Shadow");  //阴影长度
                          if (c_sPx!=null)
                              sPx = Integer.parseInt(c_sPx);
                          int sunAngle = 0;  //太阳照射角度
                          String s_sunAngle = layer.get("SunAngle");
                          if (s_sunAngle!=null)
                              sunAngle = Integer.parseInt(s_sunAngle);
                          double sCon =Math.toRadians(angle+offset-sunAngle);
                          float sX = (float)(Math.sin(sCon)*sPx);  //x坐标
                          float sY = (float)(Math.cos(sCon)*sPx);  //y坐标
                          if (!this.pics.containsKey(picShadow)){
                              //内存中没有图片的时候，先加载一下图片吧
                              this.pics.put(picShadow,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+picShadow));
                          }
                          canvas.drawBitmap(this.pics.get(picShadow),PosX+sX, PosY+sY, null);
                          //这里处理指针的左右阴影
                          if(picRight!=null){
                              if (sunAngle<0){
                                  if(angle+offset>360+sunAngle&&angle+offset<=360||angle+offset>=0&&angle+offset<360+sunAngle-180)
                                      pic = picRight;  //右阴影
                              }else{
                                  if (angle+offset>sunAngle&&angle+offset<sunAngle+180)
                                      pic = picRight;  //右阴影
                              }
                          }
                      }
                  }else if(Content.contains("{Battery.Charging}")){
                      //电池充电图标
                      pic = layer.get("Pic");
                      if (!mBCharge)
                          continue;  //没在充电就直接跳过吧
                  }else if (Content.contains("{Step}")){
                      String[] pics = layer.get("Pic").split(",");
                      if (mStep>=10000){
                          pic = pics[pics.length-1];
                      }else{
                          pic = pics[mStep/(10000/pics.length)];
                      }
                  }else if (Content.contains("{Step.Spin}")){
                      String[] pics = layer.get("Pic").split(",");
                      String picRight=null;
                      String picShadow=null;
                      if (pics.length==2){
                          //这个是有阴影
                          pic = pics[0];   //指针
                          picShadow = pics[1];  //阴影
                      }else if(pics.length>=3){
                          //这个是有阴影，指针还有左右两面
                          pic = pics[0];  //左面
                          picRight = pics[1];  //右面
                          picShadow = pics[2];  //阴影
                      }else{
                          pic = layer.get("Pic");
                      }
                      float angle = spinAngle/10000.0f;  //10000的总步数
                      float offset=0;
                      if (align.equals("center")){
                          offset = -angle/2;
                      }else if (align.equals("left")){
                          offset = -angle;
                      }
                      if (!this.pics.containsKey(pic)){
                          //内存中没有图片的时候，先加载一下图片吧
                          this.pics.put(pic,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+pic));
                      }
                      float newX = PosX+this.pics.get(pic).getWidth()/2;
                      float newY = PosY+this.pics.get(pic).getHeight()/2;
                      canvas.translate(newX,newY);
                      canvas.rotate(mStep*angle+offset);  //旋转的角度
                      canvas.translate(-newX,-newY);
                      //看看这里准备画一下阴影试一下
                      if (picShadow!=null){
                          int sPx = 10;  //阴影长(三角形斜边),默认10吧
                          String c_sPx = layer.get("Shadow");  //阴影长度
                          if (c_sPx!=null)
                              sPx = Integer.parseInt(c_sPx);
                          int sunAngle = 0;  //太阳照射角度
                          String s_sunAngle = layer.get("SunAngle");
                          if (s_sunAngle!=null)
                              sunAngle = Integer.parseInt(s_sunAngle);
                          double sCon =Math.toRadians(angle+offset-sunAngle);
                          float sX = (float)(Math.sin(sCon)*sPx);  //x坐标
                          float sY = (float)(Math.cos(sCon)*sPx);  //y坐标
                          if (!this.pics.containsKey(picShadow)){
                              //内存中没有图片的时候，先加载一下图片吧
                              this.pics.put(picShadow,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+picShadow));
                          }
                          canvas.drawBitmap(this.pics.get(picShadow),PosX+sX, PosY+sY, null);
                          //这里处理指针的左右阴影
                          if(picRight!=null){
                              if (sunAngle<0){
                                  if(angle+offset>360+sunAngle&&angle+offset<=360||angle+offset>=0&&angle+offset<360+sunAngle-180)
                                      pic = picRight;  //右阴影
                              }else{
                                  if (angle+offset>sunAngle&&angle+offset<sunAngle+180)
                                      pic = picRight;  //右阴影
                              }
                          }
                      }
                  }else if (Content.contains("{Weather}")){  //天气
                      pic = layer.get("Pic");
                      String picName = pic.substring(0,pic.indexOf("."));
                      String picEnd = pic.replace(picName,"");
                      pic = picName+mWeatherIndex+picEnd;
                      if (!new File(sdCard+"/zylWatchFace/"+cName+"/"+pic).exists())
                          canDraw = false;
                  }else if (Content.contains("{StopWatch}")){
                      //再来个格式吧
                      String s_format = layer.get("Format");
                      if (s_format==null)
                          s_format = "60s";  //默认等于60秒
                      int minute=-1;
                      int second=-1;
                      if(s_format.contains("m")){
                          minute = Integer.parseInt(s_format.replace("m",""));
                      }else if(s_format.contains("s")){
                          second = Integer.parseInt(s_format.replace("s",""));
                      }
                      //计时器
                      StopWatch stopWatch;
                      //联动-关联同一个计时器
                      String s_refId=layer.get("RefId");
                      if (s_refId!=null){
                          if (stopWatches.containsKey("RefId"+s_refId)){
                              stopWatch = stopWatches.get("RefId"+s_refId);
                              if (second!=-1){
                                  stopWatch.setSecond(second);
                              }
                              if (minute!=-1){
                                  stopWatch.setMinute(minute);
                              }
                          }else{
                              stopWatch = new StopWatch(minute==-1?0:minute,second==-1?0:second);
                              stopWatches.put("RefId"+s_refId,stopWatch);
                          }
                      }else{
                          if (stopWatches.containsKey("layer_"+i)){
                              stopWatch = stopWatches.get("layer_"+i);
                          }else{
                              stopWatch = new StopWatch(minute==-1?0:minute,second==-1?0:second);
                              stopWatches.put("layer_"+i,stopWatch);
                          }
                      }
                      pic = layer.get("Pic");
                      String s_handType = layer.get("HandType");
                      if (s_handType==null)
                          s_handType = "run";

                      if (!pics.containsKey(pic)){
                          //内存中没有图片的时候，先加载一下图片吧
                          pics.put(pic,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+pic));
                      }
                      float newX = PosX+this.pics.get(pic).getWidth()/2;
                      float newY = PosY+this.pics.get(pic).getHeight()/2;
                      canvas.translate(newX,newY);
                      float angle=0;
                      if (second!=-1){
                          if (s_handType.equals("run")){
                              angle = stopWatch.getSecondSweepAngle();
                          }else{
                              angle = stopWatch.getSecondWalkAngle();
                          }
                      }else if (minute!=-1){
                          if (s_handType.equals("run")){
                              angle = stopWatch.getMinuteSweepAngle();
                          }else{
                              angle = stopWatch.getMinuteWalkAngle();
                          }
                      }
                      canvas.rotate(angle);
                      canvas.translate(-newX,-newY);
                      //点击的情况
                      String touch = layer.get("Touch");  //默认显示情况
                      boolean swWork = true;  //计时器是否响应点击事件
                      if (touch!=null&&touch.equals("show")){
                          if (pics_hide.contains(i+"")){
                              swWork = false;
                          }
                      }else if (touch!=null&&touch.equals("hide")){
                          if (!pics_hide.contains(i+"")){
                              swWork = false;
                          }
                      }
                      String s_touchTime = layer.get("TouchTime");
                      int i_touchTime = 1;
                      if (s_touchTime!=null){
                          i_touchTime = Integer.parseInt(s_touchTime);
                      }
                      if (swWork&&isTouch&&touchTime==i_touchTime){
                          int trX = (int)PosX;
                          int trY = (int)PosY;
                          int trW = this.pics.get(pic).getWidth();
                          int trH = this.pics.get(pic).getHeight();
                          String touchRange = layer.get("TouchRange");  //可以自定义位置
                          if (touchRange!=null){
                              String[] touchRect = touchRange.split(",");
                              trX = Integer.parseInt(touchRect[0]);
                              trY = Integer.parseInt(touchRect[1]);
                              trW = Integer.parseInt(touchRect[2]);
                              trH = Integer.parseInt(touchRect[3]);
                          }
                          if (touchX>=trX&&touchX<=trX+trW
                                  &&touchY>=trY&&touchY<=trY+trH){
                              //这里点击成功了
                              if (stopWatch.getState()==0)
                                  stopWatch.start();
                              else if (stopWatch.getState()==1)
                                  stopWatch.stop();
                              else if (stopWatch.getState()==2)
                                  stopWatch.reset();
                          }
                      }
                  }
                  //这里判断是否显示吧
                  String touch = layer.get("Touch");
                  String touchRange = layer.get("TouchRange");
                  String s_touchTime = layer.get("TouchTime");
                  String s_touchApp = layer.get("TouchApp");  //点击打开app
                  String s_touchAppRange = layer.get("TouchAppRange");
                  int i_touchTime = 1;
                  if (s_touchTime!=null){
                      i_touchTime = Integer.parseInt(s_touchTime);
                  }
                  if (touch!=null&&touchRange!=null&&isTouch&&this.touchTime==i_touchTime){
                      String[] touchRect = touchRange.split(",");
                      int trX = Integer.parseInt(touchRect[0]);
                      int trY = Integer.parseInt(touchRect[1]);
                      int trW = Integer.parseInt(touchRect[2]);
                      int trH = Integer.parseInt(touchRect[3]);
                      if (touchX>=trX&&touchX<=trX+trW
                              &&touchY>=trY&&touchY<=trY+trH){
                          //如果正好在图片所在范围，那么就触发一下显示/隐藏吧
                          if (touch.equals("show")){
                              if (!pics_hide.contains(i+"")){
                                  pics_hide.add(i+"");
                              }else{
                                  pics_hide.remove(i+"");
                              }
                          }else if (touch.equals("hide")){
                              if (pics_hide.contains(i+"")){
                                  pics_hide.remove(i+"");
                              }else{
                                  pics_hide.add(i+"");
                              }
                          }
                      }
                      //app点击范围分开来吧，默认跟着TouchRange
                      if (s_touchAppRange!=null){
                          touchRect = s_touchAppRange.split(",");
                          trX = Integer.parseInt(touchRect[0]);
                          trY = Integer.parseInt(touchRect[1]);
                          trW = Integer.parseInt(touchRect[2]);
                          trH = Integer.parseInt(touchRect[3]);
                      }
                      if (touchX>=trX&&touchX<=trX+trW
                              &&touchY>=trY&&touchY<=trY+trH){
                          //如果正好在图片所在范围，那么就触发一下显示/隐藏吧
                          if (touch.equals("show")){
                              if (!pics_hide.contains(i+"")){
//                                  pics_hide.add(i+"");
                                  //这里显示的时候点击成功了,调用app
                                  if (s_touchApp!=null)
                                      AppTools.startApp(mContext,s_touchApp);
                              }else{
//                                  pics_hide.remove(i+"");
                              }
                          }else if (touch.equals("hide")){
                              if (pics_hide.contains(i+"")){
//                                  pics_hide.remove(i+"");
                              }else{
//                                  pics_hide.add(i+"");
                                  //这里显示的时候点击成功了,调用app
                                  if (s_touchApp!=null)
                                      AppTools.startApp(mContext,s_touchApp);
                              }
                          }else if (touch.equals("all")){  //不做显示隐藏触发
                              //这里是指显示的时候点击成功了
                              if (s_touchApp!=null)
                                  AppTools.startApp(mContext,s_touchApp);
                          }
                      }
                  }
                  //没有点击的情况处理
                  if (touch!=null&&touch.equals("show")){
                      if (pics_hide.contains(i+"")){
                          canDraw = false;
                      }
                  }else if (touch!=null&&touch.equals("hide")){
                      if (!pics_hide.contains(i+"")){
                          canDraw = false;
                      }
                  }
                  if (canDraw){
                      if (!pics.containsKey(pic)){
                          //内存中没有图片的时候，先加载一下图片吧
                          pics.put(pic,BitmapFactory.decodeFile(sdCard+"/zylWatchFace/"+cName+"/"+pic));
                      }
                      canvas.drawBitmap(pics.get(pic),PosX, PosY, null);
                  }
              }else{
                  Log.d("zyltest","未知类型的层");
              }
              canvas.restore();
          }
          //调试用。。。
//          if (isTouch){
//              this.mPaint.setColor(Color.RED);
//              canvas.drawText(touchTestX+","+touchTestY+"|"+touchTestX1+","+touchTestY1, 1, 200, this.mPaint);
//          }
      }catch (Exception e){
          String content = "";
          if (e_layer!=null){
              if (e_layer.get("Content")!=null){
                  content = e_layer.get("Content");
              }
          }
          this.mPaint.setColor(Color.RED);
          this.mPaint.setTypeface(Typeface.createFromAsset(mContext.getAssets(), "fonts/fzltqianhei_light.ttf"));
          this.mPaint.setTextSize(24);
          canvas.drawText("第"+i+"个层出错", 10, 170, this.mPaint);
          canvas.drawText("Content="+content, 10, 200, this.mPaint);
          canvas.drawText(e.getMessage(), 10, 230, this.mPaint);
//          Toast.makeText(getContext(),"第"+i+"个层出错,Content="+content+","+e.getMessage(),Toast.LENGTH_LONG).show();
          e.printStackTrace();
      }

      if (isTouch){
          isTouch = false;  //直接结束掉
          touchTime = 0;
          touchX = -1;
          touchY = -1;
      }
  }

//  private void doNightDraw(Canvas canvas){
//      doDayDraw(canvas,"night");
//  }

  protected void onDraw(Canvas paramCanvas)
  {
//    super.onDraw(paramCanvas);
      paramCanvas.drawColor(Color.BLACK);  //画黑色的背景...试试看
    try {
      this.mCommonUtils.setDrawFilter(paramCanvas);  //抗锯齿设置
      this.mCommonUtils.setTimeToNow();

        if (isDimRunning) {
            //只画dim层
            doDayDraw(paramCanvas,"dim");
        }else{
            int cHour = Integer.parseInt(this.mCommonUtils.getHourOfString());
            if (DayHour.equals(NightHour)){
                doDayDraw(paramCanvas,"day");  //白天画图
            }else if (Integer.parseInt(DayHour)<Integer.parseInt(NightHour)){
                if (cHour>=Integer.parseInt(DayHour)
                        &&cHour<=Integer.parseInt(NightHour)){
                    doDayDraw(paramCanvas,"day");  //白天画图
                }else{
                    doDayDraw(paramCanvas,"night");  //晚上画图
                }
            }else if (Integer.parseInt(DayHour)>Integer.parseInt(NightHour)){
                if (cHour>=Integer.parseInt(NightHour)
                        &&cHour<=Integer.parseInt(DayHour)){
                    doDayDraw(paramCanvas,"night");  //晚上画图

                }else{
                    doDayDraw(paramCanvas,"day");  //白天画图
                }
            }
        }



//    initTextXY();
//    this.mCommonUtils.setDrawFilter(paramCanvas);
//    this.mCommonUtils.setTimeToNow();
//    if (showSecondType.equals("run")){
//      this.mSecondAngle = ((this.mCommonUtils.getSecondSweepAngle()) % 360.0F);
//    }else{
//      this.mSecondAngle = this.mCommonUtils.getSecondWalkAngle();
//    }
//    this.mMinuteAngle = ((this.mCommonUtils.getMinuteSweepAngle()) % 360.0F);
//    this.mHourAngle = ((this.mCommonUtils.getHourSweepAngle()) % 360.0F);
//      if (!this.isDoze) {
//        doLightDraw(paramCanvas);
//      }else{
//        doDimDraw(paramCanvas);
//      }
//    for (;;)
//    {
      if (this.dozeCallback != null)
      {
        this.dozeCallback.onCallbackFinished();
        this.dozeCallback = null;
      }
    }catch (Exception e){
      Log.d("zyltest","onDraw有异常...");
      e.printStackTrace();
    }

  }

    private boolean isTouch = false;   //是否有用户点击表盘
    private int touchTime = 0;  //1：单击，2：双击
    private float touchX = -1;
    private float touchY = -1;
    private float touchTestX = -1;
    private float touchTestY = -1;
    private float touchTestX1 = -1;
    private float touchTestY1 = -1;
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        //点击测试
        if (isDim){
            //如果有dim模式，触摸屏幕的时候把它退出来吧
            isDimRunning = false;
//            Log.d("zyltest","onTouchEvent saveScreenBrightness");
            FashionFace.changeMySelf = false;
            ZylUtils.saveScreenBrightness(mContext,FashionFace.cBrightness);  //恢复亮度试试看
//            ZylUtils.changeAppBrightness(mContext,FashionFace.cBrightness);
            this.mHandler.removeMessages(15001);  //dim重新计时
            this.mHandler.sendEmptyMessageDelayed(15001,this.dimEnterTime*1000);  //15秒后触发
            this.mHandler.sendEmptyMessage(1);   //点击就刷新一次屏幕算了。。
        }
        Log.d("zyltest onTouch:",event.toString());
        touchTestX = event.getX();
        touchTestY = event.getY();
        //表盘点击事件
        if (!isTouch && event.getAction() == MotionEvent.ACTION_DOWN){
            touchTime = touchTime+1;
            Message msg = new Message();
            msg.what = 1001;
            msg.obj = event;
            this.mHandler.sendMessageDelayed(msg,300);
//            touchX = event.getX();
//            touchY = event.getY();
//            isTouch = true;
        }
        return super.onTouchEvent(event);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        Log.d("zyltest keydnow",keyCode+"||"+event);
        return super.onKeyDown(keyCode, event);
    }

    public void registBroadcast()
  {
    IntentFilter localIntentFilter = new IntentFilter();
    localIntentFilter.addAction("android.intent.action.DATE_CHANGED");
    localIntentFilter.addAction("Action.Tws.WatchTimeChanged");
    localIntentFilter.addAction("Action.Tws.LbsGetWeatherResult");
    localIntentFilter.addAction("android.intent.action.BATTERY_CHANGED");
    localIntentFilter.addAction("android.intent.action.ACTION_POWER_CONNECTED");
    localIntentFilter.addAction("android.intent.action.ACTION_POWER_DISCONNECTED");
    localIntentFilter.addAction("Action.Tws.device_connected");
      localIntentFilter.addAction("Action.Tws.StepGoal");  //步数
      localIntentFilter.addAction("Action.response.healthkit");   //健康步数广播
    localIntentFilter.addAction("cn.zyl.watchface.change");  //自己的表盘切换广播
//    localIntentFilter.addAction("cn.zyl.watchface.change.stop");  //自己的表盘切换广播
    this.mBReceiver.registerReceiver(localIntentFilter);
  }
  
  public void resetDozeMode()
  {
    this.isDoze = false;
    invalidate();
  }
  
  public void startHandler()
  {
//    initTextXY()
      if (isDim&&!isDimRunning){
//          //手转动就退出dim模式,这个暂时先不要吧？
//          isDimRunning = false;
//          this.mHandler.removeMessages(15001);
          this.mHandler.sendEmptyMessageDelayed(15001,this.dimEnterTime*1000);
      }
    this.mHandler.sendEmptyMessage(1);
      if (!isDimRunning)  //非dim模式更新
    this.mHandler.sendEmptyMessageDelayed(2, 10000L);  //抬手后10秒更新天气吧
  }
  
  public void stopHandler()
  {
    this.mHandler.removeMessages(1);
    this.mHandler.removeMessages(2);
      this.mHandler.removeMessages(15001);
      //这里要考虑一下直接进入dim模式
//      if (isDim){
//          this.mHandler.sendEmptyMessage(15001);
//      }
  }
  
  public void unbindLBSService()
  {
    this.mServiceConnection.unbindService();
  }
  
  public void unloadBitmapRes()
  {
      frameTop = 15;  //初始化15帧
    this.pics.clear();   //清空先
    this.fonts.clear();   //清空先
    this.layers.clear();   //清空先
      this.pics_hide.clear();  //清空
      this.stopWatches.clear();  //清空
      this.spins.clear();
      this.switchs.clear();
      this.RVLT_framesjump.clear();
      this.RVLT_spins.clear();
//    if ((this.mBg != null) && (!this.mBg.isRecycled()))
//    {
//      this.mBg.recycle();
//      this.mBg = null;
//    }
//    if ((this.mHourNeedle != null) && (!this.mHourNeedle.isRecycled()))
//    {
//      this.mHourNeedle.recycle();
//      this.mHourNeedle = null;
//    }
//    if ((this.mMinuteNeedle != null) && (!this.mMinuteNeedle.isRecycled()))
//    {
//      this.mMinuteNeedle.recycle();
//      this.mMinuteNeedle = null;
//    }
//    if ((this.mSecondNeedle != null) && (!this.mSecondNeedle.isRecycled()))
//    {
//      this.mSecondNeedle.recycle();
//      this.mSecondNeedle = null;
//    }
//    if ((this.mBatteryCharging != null) && (!this.mBatteryCharging.isRecycled()))
//    {
//      this.mBatteryCharging.recycle();
//      this.mBatteryCharging = null;
//    }
//    if ((this.mBatteryFull != null) && (!this.mBatteryFull.isRecycled()))
//    {
//      this.mBatteryFull.recycle();
//      this.mBatteryFull = null;
//    }
//    if ((this.mBatteryHigh != null) && (!this.mBatteryHigh.isRecycled()))
//    {
//      this.mBatteryHigh.recycle();
//      this.mBatteryHigh = null;
//    }
//    if ((this.mBatteryLow != null) && (!this.mBatteryLow.isRecycled()))
//    {
//      this.mBatteryLow.recycle();
//      this.mBatteryLow = null;
//    }
//    if ((this.mBatteryMiddle != null) && (!this.mBatteryMiddle.isRecycled()))
//    {
//      this.mBatteryMiddle.recycle();
//      this.mBatteryMiddle = null;
//    }
//    if ((this.mBatteryWaring != null) && (!this.mBatteryWaring.isRecycled()))
//    {
//      this.mBatteryWaring.recycle();
//      this.mBatteryWaring = null;
//    }
//    if ((this.mDimBg != null) && (!this.mDimBg.isRecycled()))
//    {
//      this.mDimBg.recycle();
//      this.mDimBg = null;
//    }
//    if ((this.mDimHourNeedle != null) && (!this.mDimHourNeedle.isRecycled()))
//    {
//      this.mDimHourNeedle.recycle();
//      this.mDimHourNeedle = null;
//    }
//    if ((this.mDimMinuteNeedle != null) && (!this.mDimMinuteNeedle.isRecycled()))
//    {
//      this.mDimMinuteNeedle.recycle();
//      this.mDimMinuteNeedle = null;
//    }
  }
  
  public void unregistBroadcast()
  {
    this.mBReceiver.unregisterReceiver();
  }

  private class BatteryStatus
  {
    private Context mContext;
    private boolean mIsCharging;
    private boolean mIsFull;
    private boolean mIsLow;
    private float mLevel;
    
    public BatteryStatus(Context paramContext)
    {
      this.mContext = paramContext;
    }
    
    public void checkBatteryState()
    {
      IntentFilter intentFilter = new IntentFilter("android.intent.action.BATTERY_CHANGED");
      Intent intent = this.mContext.registerReceiver(null,intentFilter);
      int status = intent.getIntExtra("status",-1);
      int scale = intent.getIntExtra("scale",100);
      showBattery100Level = intent.getIntExtra("level",scale);
      if (status!=2 && status!=5){
        this.mIsCharging = false;
        FashionBaseView.this.mBCharge = false;
      }else{
        this.mIsCharging = true;
        FashionBaseView.this.mBCharge = true;
      }
      this.mLevel = ((float) showBattery100Level) / scale;
      if ((this.mLevel >= 0.1D)) {
        this.mIsLow = false;
        this.mIsFull = true;
      } else {
        this.mIsLow = true;
        this.mIsFull = false;
      }
//      switch (((Intent)localObject).getIntExtra("status", -1))
//      {
//      }
////      for (;;)
////      {
//        int i = ((Intent)localObject).getIntExtra("scale", 100);
//        this.mLevel = (((Intent)localObject).getIntExtra("level", i) / i);
////        if (this.mLevel >= 0.1D) {
////          break;
////        }
//        this.mIsLow = true;
////        return;
//        this.mIsCharging = true;
//        FashionBaseView.this.mBCharge = true;
////        continue;
//        this.mIsCharging = false;
//        FashionBaseView.this.mBCharge = false;
//      }
//      this.mIsLow = false;
    }
  }
}


/* Location:              E:\zyl\ylwork\Android\Android_Decode\apk2java\apktool2.1.0\WatchFaceBlackFashion\classes-dex2jar.jar!\com\example\watchfaceblackfashion\FashionBaseView.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */